If-Then-Else
Chooses between alternative paths of execution.
Syntax
if condition then statement; {statement;}
{ elseif condition then statement; {statement;} }
[else statement; {statement;}]
endif
condition
Specifies a Boolean expression with a value of TRUE, FALSE, or UNKNOWN (in the case of expressions involving Null values). This condition is tested to determine which set of statements is executed.
Description
The 4GL if-then-else statement combination establishes a variety of logical relationships, which you can use to control the flow of an application, through Boolean expressions. The if-then-else statement combination is the simplest form of flow-control statement, letting you choose between alternate paths of execution in response to the data you enter.
Boolean expressions can include comparison operators and the logical operators AND, OR, and NOT. Boolean expressions involving Null values can evaluate to Unknown. Any Boolean expression whose result is Unknown behaves exactly as if it evaluated to False.
You can nest two or more if statements. In such cases, each if statement must be closed with its own endif statement.
The following are If-Then-Else combinations:
if-then-endif
The if statement tests for the truth of an expression:
True
4GL executes the statements from the keyword then to the endif statement.
False or Unknown
4GL executes the statements after the endif statement.
if-then-else-endif
The if statement tests for the truth of an expression:
True
4GL executes the set of statements from the keyword then to the keyword else.
False or Unknown
4GL executes the statements from the keyword else to the keyword endif.
if-then-elseif-then-else-endif
The if statement tests for the truth of an expression:
True
4GL executes the set of statements from the keyword then to the keyword elseif.
False or Unknown
The interpreter tests another expression, which starts with the keyword else or elseif up to the keyword endif.
You can use one or multiple elseif statements.
Examples
Print message if no employee number was entered in the empnum field:
if empnum = 0 then
message 'Please enter employee number';
sleep 3;
endif;
Control the flow of frames within an application based on the value in the status field in the current form:
if status = n then
callframe new;
elseif status = c then
callframe completed;
else
callframe inprogress;
endif;
Nest multiple if statements:
if status = 'n' then
if empnum = 0 then
message 'Please enter employee number';
sleep 3;
else
callframe NewEmp
endif;
endif;