CONTINUE v15

The CONTINUE statement provides a way to proceed with the next iteration of a loop while skipping intervening statements.

When the CONTINUE statement is encountered, the next iteration of the innermost loop begins, skipping all statements following the CONTINUE statement until the end of the loop. That is, control is passed back to the loop control expression, if any, and the body of the loop is reevaluated.

If you use the WHEN clause, then the next iteration of the loop begins only if the specified expression in the WHEN clause evaluates to TRUE. Otherwise, control is passed to the statement following the CONTINUE statement.

You can use the CONTINUE statement only inside a loop.

This example uses the CONTINUE statement to skip the display of the odd numbers:

DECLARE
    v_counter       NUMBER(2);
BEGIN
    v_counter := 0;
    LOOP
        v_counter := v_counter + 1;
        EXIT WHEN v_counter > 10;
        CONTINUE WHEN MOD(v_counter,2) = 1;
        DBMS_OUTPUT.PUT_LINE('Iteration # ' || v_counter);
    END LOOP;
END;

The following is the output from this example:

Output
Iteration # 2
Iteration # 4
Iteration # 6
Iteration # 8
Iteration # 10