IF
The IF
instruction executes a group of
statements conditionally.
Syntax
IF condition THEN
statement
[...]
[ ELSE
statement
[...]
]
END IF
- condition is a boolean expression.
- statement is any instruction supported by the language.
Usage
If condition is TRUE
,
the runtime system executes the block of statements following the THEN
keyword,
until it reaches either the ELSE
keyword or the END
IF
keywords and resumes execution after the END IF
keywords.
If condition is FALSE
, the
runtime system executes the block of statements between the ELSE
keyword
and the END IF
keywords. If ELSE
is
absent, it resumes execution after the END IF
keywords.
By
default, the runtime system evaluates all part of the condition. The
semantics of boolean expressions can be controlled by the OPTIONS
SHORT CIRCUIT
compiler directive, to reduce expression evaluation
when using AND
/ OR
operators.
A NULL
expression
is considered as FALSE
. Use the IS NULL
keyword
to test if an expression is null.
Example
MAIN
DEFINE name CHAR(20)
LET name = "John Smith"
IF name MATCHES "John*" THEN
DISPLAY "The name starts with [John]!"
ELSE
DISPLAY "The name is " || name || "."
END IF
END MAIN