O'Reilly logo

Visual Basic® 2010 Programmer's Reference by Rod Stephens

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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:

If condition Then statement

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required