CONTINUE

CONTINUE (or ITERATE) skips the rest of the statements in the iteration of a loop and starts the next iteration of the loop.

For more information on terminating the current iteration of a loop, see Terminating an Iteration Without Terminating the Loop.

See also

BREAK

Syntax

{ CONTINUE | ITERATE } [ <label> ] ;

Where:

label

An optional label. If the label is specified, the CONTINUE will start at the first statement in the loop with the label.

You can use this to continue more than one level higher in a nested loop or a nested branch.

Usage Notes

  • CONTINUE and ITERATE are synonymous.

  • If the loop is embedded in another loop(s), you can break out of not only the current loop and start from the first statement in the enclosing loop by including the enclosing loop’s label as part of the CONTINUE. For an example, see the examples section below.

Examples

The following loop iterates 3 times. Because the code after the CONTINUE statement is not executed, the variable named counter2 will be 0 rather than 3.

DECLARE
  counter1 NUMBER(8, 0);
  counter2 NUMBER(8, 0);
BEGIN
  counter1 := 0;
  counter2 := 0;
  WHILE (counter1 < 3) DO
    counter1 := counter1 + 1;
    CONTINUE;
    counter2 := counter2 + 1;
  END WHILE;
  RETURN counter2;
END;

Note: If you are using SnowSQL or the classic web interface, use this example instead (see Using Snowflake Scripting in SnowSQL and the Classic Web Interface):

EXECUTE IMMEDIATE $$
DECLARE
    counter1 NUMBER(8, 0);
    counter2 NUMBER(8, 0);
BEGIN
    counter1 := 0;
    counter2 := 0;
    WHILE (counter1 < 3) DO
        counter1 := counter1 + 1;
        CONTINUE;
        counter2 := counter2 + 1;
    END WHILE;
    RETURN counter2;
END;
$$;

Here is the output of executing the example:

+-----------------+
| anonymous block |
|-----------------|
|               0 |
+-----------------+
Back to top