MYSQL WHILE LOOP CONTINUE is not recognized MYSQL WHILE LOOP CONTINUE is not recognized database database

MYSQL WHILE LOOP CONTINUE is not recognized


ITERATE is what you want. In a comment, you mentioned

ITERATE is start loop again, from first value, i need to skip some value

That is NOT the case. ITERATE is equivalent to the concept of continue. Your loop was "starting over" (really, running indefinitely) because originally you had:

 loop_4: WHILE v1 > 0 DO        IF (v1 = 4) THEN            CONTINUE loop_4;        END IF;        SET res = CONCAT(res, ", ", v1);        SET v1 = v1 - 1;    END WHILE loop_4;

Which says, when v1 is 4, go back to loop_4 - the value of v1 here is unchanged, so it will infinitely return to loop_4 with v1=4 then enter that if and start over again. As this is a while loop, you need to decrement v1 on your own inside the if, e.g.:

mysql> delimiter $$mysql> CREATE PROCEDURE loop_2()    -> BEGIN    ->     DECLARE v1 INT;    ->     DECLARE res TEXT;    ->     SET v1 = 5;    ->     SET res = "ok ";    ->     loop_4: WHILE v1 > 0 DO    ->         IF (v1 = 4) THEN    ->              SET v1 = v1 - 1;    ->              ITERATE loop_4;    ->         END IF;    ->         SET res = CONCAT(res, ", ", v1);    ->         SET v1 = v1 - 1;    ->     END WHILE loop_4;    ->     SELECT res;    -> END $$Query OK, 0 rows affected (0.00 sec)mysql> delimiter ;mysql> call loop_2();+-----------------+| res             |+-----------------+| ok , 5, 3, 2, 1 |+-----------------+1 row in set (0.00 sec)Query OK, 0 rows affected (0.00 sec)