Specifying a Labelled FOR Loop
About this task
CREATE PROCEDURE ex_cont_ex() DEFINE i,s,j, INT; <<for_lab>> FOR j = 1 TO 20 IF j > 10 THEN CONTINUE FOR; END IF LET i,s = j,0; WHILE i > 0 LET i = i -1; IF i = 5 THEN EXIT for_lab; END IF END WHILE END FOR for_lab END PROCEDURE;
Here the EXIT for_lab
statement
has the same effect that the EXIT
or EXIT
FOR
keywords would have, terminating both the FOR loop and
the routine. In this example, the statement that includes the EXIT
for_lab
statement has the same effect that EXIT for_lab
WHEN i = 5
would have.
You can also label a LOOP statement that begins with a loop <<label>> specification that immediately precedes the initial FOR keyword. In this type of loop, the CONTINUE LOOP, EXIT LOOP, and END LOOP keywords replace the CONTINUE FOR, EXIT FOR, and END FOR keywords. Both the LOOP and FOR keywords are optional after the CONTINUE and EXIT keywords, but the END LOOP keywords are required in SPL loop statements that include the LOOP keyword.
You can use similar syntax to create an unlabeled loop that omits the <<label>> specification that immediately precedes the initial FOR keyword. In this case, you must also omit the undelimited loop label identifier that follows the END LOOP keywords. See the LOOP statement for a description and examples of these forms of labeled and unlabeled loop statements that enable you to combine FOR statement syntax, with a finite number of loop iterations, with the "loop forever" syntax of the LOOP statement.