WHILE Loop
- Last UpdatedJul 13, 2023
- 1 minute read
WHILE loop performs a function or set of functions within a script several times during a single execution of a script while a condition is true. The general format of the WHILE loop is as follows:
WHILE <Boolean_expression>
[statements]
[EXIT WHILE;]
[statements]
ENDWHILE;
Where: Boolean_expression is an expression that can be evaluated as a Boolean as defined in the description of IF…THEN statements.
It is possible to exit the loop from the body of the loop through the EXIT WHILE statement.
The WHILE loop is executed as follows:
-
The script evaluates whether the Boolean_expression is true or not. If not, program execution exits the loop and continues after the ENDWHILE statement.
-
The statements in the body of the loop are executed. The loop can be exited through the EXIT WHILE statement.
-
Steps 1 through 2 are repeated.
WHILE loops can be nested. The number of levels of nesting possible depends on memory and resource availability.