User's Guide
Part VI. SQL Anywhere Reference
Chapter 43. Watcom-SQL StatementsRepeat the execution of a statement list.
[ statement-label : ]
...[ WHILE search-condition ] LOOP
... statement-list
...END LOOP [ statement-label ]
Procedures, triggers, and batches.
None.
None.
The WHILE and LOOP statements are control statements that allow you to repeatedly execute a list of SQL statements while a search-condition evaluates to TRUE. The LEAVE statement can be used to resume execution at the first statement after the END LOOP.
If the ending statement-label is specified, it must match the beginning statement-label.
A While loop in a procedure.
...SET i = 1 ;WHILE i <= 10 LOOPINSERT INTO Counters( number ) VALUES ( i ) ;SET i = i + 1 ;END LOOP ;...
A labeled loop in a procedure.
SET i = 1;lbl:LOOPINSERTINTO Counters( number )VALUES ( i ) ;IF i >= 10 THENLEAVE lbl ;END IF ;SET i = i + 1 ;END LOOP lbl