Pre-General Availability Draft: 2017-11-23
[begin_label:] LOOP statement_list END LOOP [end_label]
LOOP implements a simple loop
construct, enabling repeated execution of the statement list,
which consists of one or more statements, each terminated by a
;) statement delimiter. The
statements within the loop are repeated until the loop is
terminated. Usually, this is accomplished with a
LEAVE statement. Within a stored
RETURN can also be
used, which exits the function entirely.
Neglecting to include a loop-termination statement results in an infinite loop.
CREATE PROCEDURE doiterate(p1 INT) BEGIN label1: LOOP SET p1 = p1 + 1; IF p1 < 10 THEN ITERATE label1; END IF; LEAVE label1; END LOOP label1; SET @x = p1; END;