LOOP statement
Last but not least, let’s move on to the LOOP statement. This statement is very similar to the WHILE and REPEAT statements, except that it does not come with a condition to exit the loop.
Instead, we use the ITERATE or LEAVE keywords to exit it.
The syntax of a LOOP statement is:
[name of loop statement :] LOOP
-- some tasks
END LOOP;
Let’s look at a few examples.
Example 1
DELIMITER $$
CREATE FUNCTION loop_demo_A(x INT, y INT) RETURNS VARCHAR(255) DETERMINISTIC
BEGIN
DECLARE z VARCHAR(255);
SET z = '';
simple_loop: LOOP
SET x = x + 1;
IF x > y THEN
LEAVE simple_loop;
END IF;
SET z = concat(z,...