Decision Constructs and the Relational/Equality
Operators
Now that you can iterate over a block of statements, the next related concept is how to control the
flow of program execution. C# defines two simple constructs to alter the flow of your program,
based on various contingencies:
• The if/else statement
• The switch statement
The if/else Statement
First up is our good friend the if/else statement. Unlike in C and C++, however, the if/else state-
ment in C# operates only on Boolean expressions, not ad hoc values such as –1, 0. Given this,
if/else statements typically involve the use of the C# operators shown in Table 3-7 in order to
obtain a literal Boolean value.
Table 3-7.
C# Relational and Equality Operators
Do'stlaringiz bilan baham: |