Making Decisions Using if Statements

By far the most common decision-making construct used in programming is the if construct. A simple if construct looks like this:

						if (expression)
   ... statement to execute when expression is true;

The if construct uses Boolean logic, as discussed in Hour 12, “Performing Arithmetic, String Manipulation, and Date/Time Adjustments,” to evaluate an expression to either true or false. The expression may be simple (if (x == 6)) or complicated (if (x==6 && y>10)). If the expression evaluates to true, the statement or block of statements (if enclosed in braces) gets executed. If the expression evaluates to false, Visual C# .NET doesn't execute the statement or statement block for the if construct.

Remember that compound ...

Get Sams Teach Yourself Microsoft® Visual C#™ .NET in 24 Hours now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.