WHILE
Use the WHILE statement to establish a loop with variable end conditions.
Syntax
(1) >>-+---------------+--WHILE--| Condition |----------------------> '-<<--label-->>-' (2) >--+-| Statement Block |------END WHILE--+-----------+------+---> | | (3) | | | '-label-----' | | (2) | '-LOOP--| Statement Block |------END LOOP--+-----------+-' | (3) | '-label-----' >--+---+------------------------------------------------------->< '-;-'
Notes:
- See Condition
- See Statement Block
- Valid only if <<label>> precedes the first WHILE keyword
Element | Description | Restrictions | Syntax |
---|---|---|---|
label | Name of the loop label for this loop | Must be unique among labels in this SPL routine | Identifier |
Usage
The condition is evaluated before the statement block first runs and before each subsequent iteration. Iterations® continue as long as the condition remains true. The loop terminates when the condition evaluates to not true.
If any expression within the condition evaluates to NULL, the condition becomes not true unless you are explicitly testing for NULL with the IS NULL operator.
If an expression within the condition has an UNKNOWN value because it references uninitialized SPL variables, an immediate error results. In this case, the loop terminates, raising an exception.