Selection statements let you selectively execute code based on some condition. Visual Basic supports two primary selection statements, If and Select Case, and two selection functions, Choose and Switch. 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 an If command is included in the output.
Put on Your Thinking Hat
To get some practice with theifstatement, 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.