CONTINUE

Use the CONTINUE statement to start the next iteration of the innermost FOR, LOOP, WHILE, or FOREACH loop.

Syntax


1  CONTINUE
1 FOR
1 FOREACH
1 LOOP
1 WHILE
2  ;

Usage

When control of execution passes to a CONTINUE statement, the SPL routine skips the rest of the statements in the innermost loop of the specified type. Execution continues at the top of the loop with the next iteration.

In the following example, the loop_skip function inserts values 3 through 15 into the table testtable. The function also returns values 3 through 9 and 13 through 15 in the process. The function does not return the value 11 because it encounters the CONTINUE FOR statement. The CONTINUE FOR statement causes the function to skip the RETURN WITH RESUME statement:
CREATE FUNCTION loop_skip()
   RETURNING INT;
   DEFINE i INT;
   ...
   FOR i IN (3 TO 15 STEP 2)
      INSERT INTO testtable values(i, null, null); 
      IF i = 11
         CONTINUE FOR;
      END IF;
      RETURN i WITH RESUME;
   END FOR;

END FUNCTION;

Just as with the EXIT statement, (EXIT), in FOREACH statements and in FOR or WHILE statements that do not include the LOOP keyword, the FOR, WHILE, or FOREACH keyword must immediately follow the CONTINUE keyword to specify the type of loop. Errors are generated if the specified type of loop does not match the context in which the CONTINUE statement is issued.

In the LOOP, FOR LOOP, and WHILE LOOP statements, whether labeled or unlabeled, a keyword indicating the type of loop is optional after the CONTINUE keyword, but HCL OneDB™ issues an error if you specify a keyword that does not correspond to the type of loop.

Related Statements

FOR, FOREACH, LOOP, WHILE