ProvideX V8.20 > Language Reference > 2. Directives
156
IF..THEN..ELSE Directive
         Test Condition
Format
1. Set Conditions: IF expression THEN.. [ELSE..] [END_IF or FI]
2. Set Conditions, Multiple Lines: IF expression THEN {...} [ELSE {...}] [END_IF or FI]
Where:
{...}
Curly braces indicating that the statements within can span multiple
lines. Must be included with both THEN and ELSE clauses (when used).
END IF
Optional terminator for the IF..THEN..ELSE structure.
ELSE
Statement executed when expression is false.
FI
Optional terminator (identical to END IF).
THEN
Statement executed when expression is true.
expression
Numeric expression to be tested for zero.
Description
Use the IF directive to control the execution of various ProvideX statements based on
the result of a Boolean expression. Refer to examples on the following page. If the value
returned by the numeric expression is not zero (true) then ProvideX continues
execution with the directives following the THEN clause up to the end of the
statement, or until an ELSE clause is encountered. If the value returned is 0 zero
(false), execution of the statement continues with the directives following the ELSE
clause (if you use it) or with the next statement.
The expression would normally include a logical operator (such as an equals =, less-than
symbol <, or the LIKE Operator, p.827), but you can use any numeric expression.
All statements within an IF..THEN..ELSE structure exist on the same line. These
statements can only span multiple lines if they are enclosed within curly brackets. A
matched set of open/closed brackets must be provided for each set of directives (
missed brackets can cause unexpected results).
Internally, when the system detects a { following the THEN clause it will continue
execution up to the next } (if true) or skip forward to it (if false). The same holds true
for the processing of the ELSE clause. Curly braces should only be used with ELSE if
they are also used with THEN. You can imbed multiple levels of mult-lined IF
directives via curly braces; however, it is important not to lose consistency.
Using END_IF
An optional END_IF (or FI) clause can be used to terminate the current IF structure
and/or to execute a common closing statement. This is particularly useful for
separating ELSE clauses in a nested IF..THEN..ELSE structure. Once the statements
that follow an END_IF clause are executed, control will fall through to the next line, or
(if nested) to the preceding level of IF..THEN..ELSE.
See Also
END_IF End IF Directive, p.116
SWITCH..CASE Branch Control, p.329
LIKE Operator, p.827
Decision Structures, User's Guide.