|
<< Click to Display Table of Contents >> Navigation: Control Commands > If...Then...Else Statement |
Description
Conditionally executes a group of statements, depending on the value of an expression.
Syntax
If condition Then statements [Else elsestatements ]
Or, you can use the block form syntax:
If condition Then
[statements]
[ElseIf condition-n Then
[elseifstatements]] . . .
[Else
[elsestatements]]
Endif
The If...Then...Else statement syntax has these parts:
Part |
Description |
condition |
One or more of the following two types of expressions: A numeric or string expression that evaluates to True or False. If condition is Null, condition is treated as False. |
statements |
One or more statements separated by colons; executed if condition is True. |
condition-n |
Same as condition. |
elseifstatements |
One or more statements executed if the associated condition-n is True. |
elsestatements |
One or more statements executed if no previous condition or condition-n expression is True. |
Remarks
You can use the single-line form (first syntax) for short, simple tests. However, the block form (second syntax) provides more structure and flexibility than the single-line form and is usually easier to read, maintain, and debug.