REPEAT (Snowflake Scripting)¶
A REPEAT loop iterates until a specified condition is true. A REPEAT loop tests the condition at
the end of the loop. This means that the body of a REPEAT loop always executes at least once.
For more information on loops, see Working with loops.
Note
This Snowflake Scripting construct is valid only within a Snowflake Scripting block.
Syntax¶
Where:
statementA statement can be any of the following:
conditionAn expression that evaluates to a BOOLEAN.
labelAn optional label. Such a label can be a jump target for a BREAK or CONTINUE statement. A label must follow the naming rules for Object identifiers.
Usage notes¶
Put parentheses around the condition in the
REPEAT. For example:REPEAT ( <condition> ).If the
conditionnever evaluates to TRUE, and the loop does not contain a BREAK command (or equivalent), then the loop will run and consume credits indefinitely.If the
conditionis NULL, then it is treated as FALSE.A loop can contain multiple statements. You can use, but are not required to use, a BEGIN … END block to contain those statements.
Examples¶
This example uses a loop to calculate a power of 2. (This is an inefficient solution, but it does demonstrate looping.)
Here is the output of executing the stored procedure: