An If
statement is the basic conditional statement. Each expression must be implicitly convertible to Boolean
. If the expression in an If
statement is True
, then the statements enclosed by the If
block are executed. If the expression is False
, then each of the ElseIf
expressions is evaluated. If one of the expressions evaluates to True
, then the corresponding block is executed. If no expression evaluates to True
and there is an Else
block, the Else
block is executed. Once a block finishes executing, execution passes to the end of the If
statement.
There is also a line version of the If
statement which has a single set of statements to be executed if the If
expression is True
and an optional set of statements to be executed if the expression is False
.
If
BooleanExpression [ Then
] StatementTerminatorEnd
If
StatementTerminatorElseIf
BooleanExpression [ Then
] StatementTerminatorElse
StatementTerminatorIf
BooleanExpression Then
[ EmbeddedStatements ]Else
EmbeddedStatements ] StatementTerminator:
[ EmbeddedStatement ]