Icon WHILE

Provides an conditional looping construct.

Syntax
[Label:]
WHILE <BooleanExpression> DO
   <StatementBlock>
END WHILE [Label];

<StatementBlock> =

<StatementBlock> =

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

Usage
Use this statement to conditionally loop on a single statement or multiple statements. 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 procedure uses an IF statement
-- to conditionally test if the State column
-- is equal to 'FL', and if so, to change it
-- to 'NY'

CREATE PROCEDURE UpdateState()
BEGIN
   DECLARE CustCursor CURSOR WITH RETURN FOR Stmt;
   DECLARE State CHAR(2) DEFAULT '';

   PREPARE Stmt FROM 'SELECT * FROM Customer';

   OPEN CustCursor;

   FETCH FIRST FROM CustCursor ('State') INTO State;

   WHILE NOT EOF(CustCursor) DO
      IF (State='FL') THEN
         UPDATE CustCursor SET 'State'='NY';
      END IF;
      FETCH NEXT FROM CustCursor ('State') INTO State;
   END WHILE;
END

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

DeviationDetails
None
Image