REPEAT Statement : Repeat until : Procedure Function MySQL TUTORIALS


MySQL TUTORIALS » Procedure Function » Repeat until »

 

REPEAT Statement


To loop over a set of statements until a post-statement condition is met, use the REPEAT statement.

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

The statement list is repeated until the search_condition is true.

A REPEAT always enters the loop at least once.

statement_list consists of one or more statements.

A REPEAT statement can be labeled.

end_label cannot be given unless begin_label also is present.

If both are present, they must be the same.

mysql>
mysql>
mysql> DELIMITER //
mysql> CREATE FUNCTION myFunction (quantity INT(10)) RETURNS INT(10)
    -> BEGIN
    ->
    ->     REPEAT
    ->     SET quantity = quantity + 1;
    ->     UNTIL quantity MOD 12 0
    ->     END REPEAT;
    ->
    ->     RETURN quantity;
    ->
    -> END
    -> //
Query OK, rows affected (0.00 sec)

mysql>
mysql> delimiter ;
mysql> select myFunction(10);
+----------------+
| myFunction(10|
+----------------+
|             12 |
+----------------+
row in set (0.00 sec)

mysql>
mysql> select myFunction(24);
+----------------+
| myFunction(24|
+----------------+
|             36 |
+----------------+
row in set (0.00 sec)

mysql>
mysql>
mysql> drop function myFunction;
Query OK, rows affected (0.00 sec)

mysql>
mysql>



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .

Follow Navioo On Twitter

MySQL TUTORIALS

 Navioo Procedure Function
» Repeat until