WHILE
Syntax
WHILE logical_expression
The general format of a WHILE command is:
WHILE logical_expression SQR_commands... [BREAK] SQR_commands... END-WHILE
Description
Begins a WHILE ... END-WHILE loop.
The WHILE loop continues until the condition being tested is FALSE.
An expression returning 0 (zero) is considered FALSE; an expression returning nonzero is TRUE.
BREAK causes an immediate exit of the WHILE loop; SQR continues with the command immediately following END-WHILE.
WHILE commands can be nested to any level and can include or be included within IF and EVALUATE commands.
Parameters
| Parameter | Description |
|---|---|
|
logical_expression |
A valid logical expression. See the LET command for a description of logical expressions. |
Example
This example shows an IF nested within a WHILE:
while #count < 50
do get_statistics
if #stat_count = 100
break ! Exit WHILE loop.
end-if
add 1 to #count
end-while
You can use single numeric variables in your expression to make your program more readable, for example, when using flags:
move 1 to #have_data
...
while #have_data
...processing...
end-while
This example sets up an infinite loop:
while 1
...processing...
if ...
break ! Exit loop
end-if
end-while
Any complex expression can be used in the WHILE command, as shown in this example:
while #count < 100 and (not #end-file or isnull(&state))
...
end-while
SeeThe LET command for a description
of expressions.