Icon REPEAT

Conditionally repeats a single statement or multiple statements.

Syntax
[Label:]
REPEAT
   <StatementBlock>
UNTIL <BooleanExpression> END REPEAT [Label];

<StatementBlock> =

<StatementBlock> =

[[Label:]
BEGIN]
   [<Statement>;]
   [<Statement>;]
[EXCEPTION]
   [<Statement>;]
[END [Label];]

Usage
Use this statement to repeat a single statement or multiple statements until a boolean expression evaluates to True. You can use the LEAVE statement to exit the loop at any time, and the ITERATE statement to jump to the top of the loop at any time.

Examples
-- This function simply repeats a
-- a string the specified number of times
-- and returns the resultant string

CREATE FUNCTION RepeatString(IN "StringToRepeat" VARCHAR, IN "RepeatCount" INTEGER)
RETURNS VARCHAR
BEGIN
   DECLARE I INTEGER DEFAULT 1;
   DECLARE Result VARCHAR DEFAULT '';

   IF RepeatCount = 0 THEN
      LEAVE;
   END IF;
   
   REPEAT
      SET Result = (Result + StringToRepeat);
      SET I = (I + 1);
   UNTIL (I > RepeatCount) END REPEAT;

   RETURN Result;
END

SQL 2003 Standard Deviations
This statement deviates from the SQL 2003 standard in the following ways:

DeviationDetails
None
Image