13.6.5.6 REPEAT Statement语句

[begin_label:] REPEAT
statement_list
UNTIL search_condition
END REPEAT [end_label]

The statement list within a REPEAT statement is repeated until the search_condition expression is true. REPEAT语句中的语句列表将重复,直到搜索条件表达式为trueThus, a REPEAT always enters the loop at least once. 因此,REPEAT总是至少进入循环一次。statement_list consists of one or more statements, each terminated by a semicolon (;) statement delimiter.statement_list由一个或多个语句组成,每个语句以分号(;)结尾语句分隔符。

A REPEAT statement can be labeled. REPEAT语句可以加标签。For the rules regarding label use, see Section 13.6.2, “Statement Labels”.有关标签使用的规则,请参阅第13.6.2节,“语句标签”

Example:例子:

mysql> delimiter //

mysql> CREATE PROCEDURE dorepeat(p1 INT)
BEGIN
SET @x = 0;
REPEAT
SET @x = @x + 1;
UNTIL @x > p1 END REPEAT;
END
//
Query OK, 0 rows affected (0.00 sec)

mysql> CALL dorepeat(1000)//
Query OK, 0 rows affected (0.00 sec)

mysql> SELECT @x//
+------+
| @x   |
+------+
| 1001 |
+------+
1 row in set (0.00 sec)