Simple LOOP Statements
The following program fragment illustrates a simple form of the LOOP statement.
LOOP
LET i = i + 1;
IF i = 5 THEN EXIT;
ELSE
CONTINUE;
END IF
END LOOP;
In this example the IF statement limits the number of iterations. Here the CONTINUE and EXIT statements omit the optional LOOP keyword, but the END LOOP statement is required at the end of the statement loop. A similar FOR or WHILE keyword would have required the FOR or WHILE keywords, respectively, in the CONTINUE and EXIT statements.The next example uses a conditional EXIT statement to terminate the loop:
LOOP
LET i = i + 1;
EXIT WHEN i = 4;
END LOOP;
No keyword identifying the type of loop statement is required after the EXIT statement, as would be the case for an EXIT statement in a FOR, WHILE, or FOREACH statement. When the i = 4
condition becomes true, program control passes from the LOOP statement to whatever statement follows the END LOOP keywords.