Nesting if statement with LOOP statement : LOOP « Procedure Function « MySQL Tutorial






mysql>
mysql> delimiter //
mysql>
mysql> create procedure increment (IN in_count INT)
    -> BEGIN
    -> declare count INT default 0;
    ->
    ->     increment: loop
    ->         set count = count + 1;
    ->         if count < 20 then
    ->             iterate increment;
    ->         end if;
    ->         if count > in_count then
    ->             leave increment;
    ->         end if;
    ->     end loop increment;
    ->     select count;
    -> END
    -> //
Query OK, 0 rows affected (0.00 sec)

mysql>
mysql> delimiter ;
mysql> call increment(3);
+-------+
| count |
+-------+
|    20 |
+-------+
1 row in set (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

mysql>
mysql> drop procedure increment;
Query OK, 0 rows affected (0.00 sec)








11.18.LOOP
11.18.1.Simple LOOP
11.18.2.Nesting if statement with LOOP statement
11.18.3.LOOP with LEAVE
11.18.4.LOOP with ITERATE
11.18.5.LOOP Statement with LEAVE