Chapter 18. Program Control Statements
Program control statements tell an application which other statements to execute under a particular set of circumstances. They control the path that execution takes through the code. They include commands that tell the program to execute some statements but not others and to execute certain statements repeatedly.
The two main categories of control statements are decision statements (or conditional statements) and looping statements. The following sections describe in detail the decision and looping statements provided by Visual Basic .NET.
DECISION STATEMENTS
A decision or conditional 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, depending on some condition. These include If, Choose, and Select Case statements.
Single-Line If Then
The single-line If Then statement has two basic forms. The first allows the program to execute a single statement if some condition is true. The syntax is as follows:
IfconditionThenstatement
If the condition is true, the program executes the statement. In the most common form of single-line If Then statement, the statement is a single simple command (such as assigning a value to a variable or calling a subroutine).
The following example checks the emp object's IsManager property. If IsManager is True, the statement sets the emp object's Salary property to 90,000.
If emp.IsManager Then emp.Salary = 90000
The ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access