Skip to main content
A control structure is a combination of keywords in code used to make a decision that alters the flow of code the computer executes.

If…then

The first control structure you should know about is If…Then. The syntax for this control structure is given as:
…where condition is some test you want to apply to the conditional structure. If the condition is true, the code within the If and End If statements is executed. If the condition is not true, the code within these statements is skipped over and does not get executed.

If…then…else

What if you want to do one thing if the condition is true but another thing if the condition is false? You could use two statements:
…but wouldn’t it be nice if you didn’t have to repeat the test. Fortunately, you have another control structure available to you in VBScript that makes this process easier. The control structure, called If…Then…Else, is represented as

Elseif

What if you had a few other cases you wanted to test? You’re in luck: You can do as many tests as you want by simply placing ElseIf statements between the first If statement and the End If statement. The syntax of such a structure looks like this:

Select case

What if you have to perform a large number of tests on the same expression? The Select statement often makes your code easier to read and interpret than would a long list of Else and Else If statements. The Select Case structure is defined as follows:
Consider an example in which you want to print a message to the user based on what state the user lives in:
Last modified on November 3, 2026