With the LOOP, EXIT, CONTINUE, WHILE, and FOR statements, you can arrange for your SPL program to repeat a series of commands.
LOOP defines an unconditional loop that is repeated indefinitely until terminated by an EXIT or RETURN statement.
is present, loop exit occurs only if the specified condition is true
, otherwise control passes to the statement after EXIT
can be used to cause early exit from all types of loops; it is not limited to use with unconditional loops.
statement provides a way to proceed with the next iteration of a loop while skipping intervening statements.
When the CONTINUE
statement is encountered, the next iteration of the innermost loop is begun, skipping all statements following the CONTINUE
statement until the end of the loop. That is, control is passed back to the loop control expression, if any, and the body of the loop is re-evaluated.
If the WHEN
clause is used, then the next iteration of the loop is begun only if the specified expression in the WHEN
clause evaluates to true
. Otherwise, control is passed to the next statement following the CONTINUE
statement may not be used outside of a loop.
statement repeats a sequence of statements so long as the condition expression evaluates to TRUE
. The condition is checked just before each entry to the loop body.
Note: The conditional expression used to determine when to exit the loop must be altered. The EXIT statement terminates the loop when its conditional expression is true. The WHILE statement terminates (or never begins the loop) when its conditional expression is false.
FOR name IN [REVERSE] expression .. expression
This form of FOR creates a loop that iterates over a range of integer values. The variable name is automatically defined as type INTEGER and exists only inside the loop. The two expressions giving the loop range are evaluated once when entering the loop. The iteration step is +1 and name begins with the value of expression to the left of .. and terminates once name exceeds the value of expression to the right of ... Thus the two expressions take on the following roles: start-value .. end-value.
The optional REVERSE
clause specifies that the loop should iterate in reverse order. The first time through the loop, name
is set to the value of the right-most expression
; the loop terminates when the name
is less than the left-most expression
Note: SPL also supports CURSOR FOR loops (see Section 3.8.7).