CONTINUE (Snowflake Scripting)

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.

Note

This Snowflake Scripting construct is valid only within a Snowflake Scripting block.

See also:

BREAK

语法

{ CONTINUE | ITERATE } [ <label> ] ;

其中:

label

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

您可以使用此选项在嵌套循环或嵌套分支中继续更高的多个级别。

使用说明

  • 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.

示例

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

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;
$$;

下面是执行示例的输出:

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