Appendix E. Control Statements
Control statements tell an application which other statements to execute under a particular set of circumstances.
The two main categories of control statements are decision statements and looping statements. The following sections describe the decision and looping statements provided by Visual Basic .NET.
DECISION STATEMENTS
A decision statement represents a branch in the program. It marks a place where the program can execute one set of statements or another or possibly no statements at all. These include If, Choose, and Select Case statements.
Single-Line If Then
A single-line If Then statement tests a condition and, if the condition is true, executes a piece of code. The code may include more than one simple statement separated by a colon.
Optional Else If clauses let the program evaluate other conditions and execute corresponding pieces of code. A final optional Else clause lets the program execute a piece of code if none of the previous conditions is true.
The syntax is as follows:
Ifcondition
Thenstatement
Ifcondition
Thenstatement1
Elsestatement2
Ifcondition1
Thenstatement1
Else Ifcondition2
Thenstatement2
_ Elsestatement3
Ifcondition
Thenstatement1
:statement2
Ifcondition
Thenstatement1
:statement2
Elsestatement3
:statement4
Complicated single-line If Then statements can be confusing and difficult to read, so I recommend using the multiline versions if the statement includes an Else clause or executes more than one statement.
Multiline ...
Get Visual Basic® 2010 Programmer's Reference 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.