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 the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.