PreviousSQL Engine Reference (v9 SP2 (9.5) revision 1) Next

WHILE

Chapter contents

Use a WHILE statement is used to control flow. It allows code to be executed repeatedly as long as the WHILE condition is true. Optionally, you may use the WHILE statement with DO and END WHILE.


Note
You cannot use a mixed syntax for the WHILE statement. You may use either WHILE with DO and END WHILE, or only WHILE. If you are using multiple statements with a WHILE condition, you must use BEGIN and END to indicate the beginning and ending of the statement blocks.

Syntax

[ label-name : ] WHILE proc-search-condition [ DO ] [ proc-stmt [; proc-
stmt ] ]... [ END WHILE ][ label-name ] 

Remarks

A WHILE statement can have a beginning label (the statement is referred to as a labeled WHILE statement).

Examples

The following example increments the variable vInteger by 1 until it reaches a value of 10, when the loop ends.

WHILE (:vInteger < 10) DO 
SET :vInteger = vInteger + 1; 
END WHILE

See Also

CREATE PROCEDURE

CREATE TRIGGER


Chapter contents
Book contents

Prev topic: USER
Next topic: Grammar Element Definitions