| You are here: | About>Computing & Technology>C / C++ / C#> C> C Tutorials> C Tutorial - Lesson Five - About Control Statements |
![]() | C / C++ / C# |
Elsewhere on the WebC Tutorial - Lesson Five - About Control StatementsControl StatementsIn this lesson, we'll be covering the major control statements which are for, while, do while,switch and if. With these under your belt, you are well on the way to becoming a seasoned programmer.
The If StatementPrograms need to make decisions. Should this statement be executed or that one? Are these parameters correct and so on. This is done using the if statement. The syntax is pretty easy.if ( conditional expression )This can be extended with else. if ( conditional expression )So if the expression is true, statement1 is executed, otherwise statement2 is executed. Here are some examples: if ( a==3 )Be Careful that you don't write = when you mean == Can you see the problem with this code? if (a=1)This will always set b to 9 as (a=1) is always true. It assigns a value of 1 to a instead of comparing a with 1. The corrected line should be this. if (a==1)This is a common mistake amongst beginners. Conditional OperatorsThis is a list of the comparisons you can make.
Previous | Next >> Elsewhere on the Web |
Las Vegas on a BudgetFind a BargainHotel DealsCheap EatsFree AttractionsEntertainment for Less |
All Topics | Email Article | Print this Page | | ![]() |
| Advertising Info | News & Events | Work at About | SiteMap | Reprints | Help | Our Story | Be a Guide |
| User Agreement | Ethics Policy | Patent Info. | Privacy Policy | ©2008 About, Inc., A part of The New York Times Company. All rights reserved. |


