WHILE statement

The WHILE statement evaluates a condition expression, and if it is TRUE executes a sequence of statements.

Syntax

Read syntax diagramSkip visual syntax diagramWhileLabel:WhileLabel
While
Read syntax diagramSkip visual syntax diagramWHILEconditionDOstatementsEND WHILE

The WHILE statement repeats the steps specified in DO provided that condition is TRUE. It is your responsibility to ensure that the logic of the program is such that the loop terminates. If condition evaluates to UNKNOWN, the loop terminates immediately.

If present, Label gives the statement a name. This has no effect on the behavior of the WHILE statement itself, but allows statements to include ITERATE and LEAVE statements or other labelled statements, which in turn include them. The second Label can be present only if the first Label is present and if it is, the labels must be identical. It is not an error for two or more labelled statements at the same level to have the same Label, but this partly negates the advantage of the second Label. The advantage is that it unambiguously and accurately matches each END with its WHILE. However, it is an error for a labelled statement within statements to have the same label, because this makes the behavior of the ITERATE and LEAVE statements ambiguous.

Example

For example:
DECLARE i INTEGER;
SET i = 1;
X : WHILE i <= 3 DO
  ...
  SET i = i + 1;
  END WHILE X;