Selection statements let you selectively execute code based on some condition. C# supports two selection statements, if and switch, and one selection operator, called the CONDITIONAL OPERATOR. Let’s start with the simplest: the if statement.
Make a Note
The if command and the #if directive have almost identical syntax, but they behave very differently. The directive controls the code that the compiler includes in the output. The command controls execution. All of the code involved in a C# if command is included in the output.
Put on Your Thinking Hat
To get some practice with the if statement, try translating these situations into code:
If x is greater than y, increment x; otherwise, set y equal to 12.
If a is equal to 5, then set x equal to 5; otherwise, if x is equal to 12, set y equal to 21, or if it’s not, set y equal to x.
 Â
You are currently reading a PREVIEW of this book.
                                                                                       Â
Get instant access to over
$1 million worth of books and videos.