Conditionally executes a
group ofstatements, depending on
the value of anexpression.
Single line syntax
Block form syntax
Block form syntaxusing
if...then...else statement syntax has these parts:
expression orstring expression that evaluates to true or false.
Optional in block
form; required in single-line form that has no else clause.
Optional. One or
more statements executed if no previous condition expression is
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.Using elseif keyword allows you to
avoid having multi-level if...endif statements when you need
Note: With the single-line form, it is possible
to have multiple statements executed as the result of an
if...then decision. All statements must be on the same line
and separated by colons, as in the following statement:
int a = 11
if a>10 then a++
A block form If
statement must be the first statement on a line. The else
and endif parts of the statement can have only
aline number orline
labelpreceding them. The block
if must end with an endif statement.
To determine whether or
not a statement is a block if, examine what follows the
then keyword. If anything
other than acomment
appears after then on the same
line, the statement is treated as a single-line if
The else is
optional. Block if statements can be nested; that is,
contained within one another.