Skip to content

IF/THEN/ELSE/FI

Conditional Test

This directive tests a condition for true or false and executes the THEN clause if true, and the ELSE clause if false. If no ELSE clause is specified, a false condition causes execution to move to the next line-numbered statement or the FI statement terminator.

IF condition [THEN] stmt [ELSE stmt] [FI]
condition
is a relational, Boolean, and/or logical expression used to establish a true or false condition.
stmt
(THEN) is the statement(s) to be executed if the condition tests true; (ELSE) is the statement(s) to be executed if the condition tests false.

The FI terminator is available starting with release level 8.0.

The syntax for the condition is:

num/str-value relational-operator num/str-value
[[logical-operator num/str-value relational-operator num/str-value]…]
or
numeric-value

num/str-value
is any valid numeric or string expression.
relational-operator
is any of the valid comparison operators listed below.
logical-operator
is any of the valid logic operators listed below.
numeric-value
is any valid numeric expression. If numeric-value is zero, this condition is false; if other than zero, true.
relational-operator meaning
= equal to
<> or >< not equal to
> greater than
< less than
>= or => greater than or equal to
<= or =< less than or equal to
logical-operator meaning
=ALL (string-value) =ALL function
LIKE string-value partial equality
OR logical OR of multiple conditionals
AND logical AND of multiple conditionals
( ) parentheses; to group multiple conditionals into specific priority order

The LIKE operator can specify a string value containing wildcards, which can match more than 1 character. LIKE automatically pads its values to the correct length.

LIKE wildcards meaning
“*” matches any string of characters (0 or more)
“?” matches a single character
“[A-Z]” matches a range for a single character
“[AGCF]” matches a single character in a list
“[wildcard]” matches the specified wildcard character
“[*]” matches the asterisk
“[?]” matches the question mark
“[[ ]” matches the left bracket without a preceding,
unmatched left bracket
“]” matches the right bracket

IF/THEN/ELSE/FI directives may be nested or strung together to form complex logical evaluations.

All IF/THEN/ELSE/FI directives are terminated by a new line-numbered statement.

IF X = 4 THEN LET Y = 7

sets Y to +7 if X contains a +4.

01000 IF TODAY < SATURDAY THEN
LET GO_TO_SCHOOL$ = "YES";
IF TODAY = TUESDAY OR TODAY = THURSDAY THEN
LET DO_LAUNDRY$ = "YES"
ELSE
LET PUT_OUT_TRASH$ = "YES"
FI
ELSE
IF TODAY = SATURDAY THEN
LET MOW_LAWN$ = "YES"
ELSE
LET WATCH_FOOTBALL$ = "YES"
FI
FI;
LET STUDY$ = "YES"

gives an example of a nested IF/THEN/ELSE/FI directive. Numeric variable TODAY is tested to establish what must be done on a given day. This logic results in GO_TO_SCHOOL$ for Monday through Friday; DO_LAUNDRY$ on Tuesday and Thursday; PUT_OUT_TRASH$ on Monday, Wednesday, and Friday; MOW_LAWN$ on Saturday; WATCH_FOOTBALL$ on Sunday; and STUDY$ every day of the week.

From the Thoroughbred Basic Language Reference, Volume II: F–Q, version 8.9.1. Open this page in the PDF