CONTINUE (Snowflake Scripting) | Snowflake Documentation (original) (raw)

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 } [ ] ;

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

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 use Snowflake CLI, SnowSQL, the Classic Console, or theexecute_stream or execute_string method in Python Connectorcode, use this example instead (see Using Snowflake Scripting in Snowflake CLI, SnowSQL, the Classic Console, and Python Connector):

EXECUTE IMMEDIATE >DECLARE>counter1NUMBER(8,0);>counter2NUMBER(8,0);>BEGIN>counter1:=0;>counter2:=0;>WHILE(counter1<3)DO>counter1:=counter1+1;>CONTINUE;>counter2:=counter2+1;>ENDWHILE;>RETURNcounter2;>END;>> 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; >>DECLARE>counter1NUMBER(8,0);>counter2NUMBER(8,0);>BEGIN>counter1:=0;>counter2:=0;>WHILE(counter1<3)DO>counter1:=counter1+1;>CONTINUE;>counter2:=counter2+1;>ENDWHILE;>RETURNcounter2;>END;>;

Here is the output of executing the example:

+-----------------+

anonymous block
0
+-----------------+