Mysql LOOP statement ********* * **************** Syntax: java code [begin_label:] LOOP statement_list end loop [end_label] instance: Java code DELIMITER $ create procedure pro_loop (p1 INT) BEGIN label1: loop set p1 = p1 + 1; IF p1 <10 then select p1 AS result; ITERATE label1; end if; SELECT 'end if' AS result; LEAVE label1; end loop label1; SET @ x = p1; SELECT @ x as result; END $ call: call pro_loop (8); output: 9, end if, 10; Description: ITERATE label1: Continue loop label1 LEAVE label1: exit label1 loop Note: The printed Code cannot be output after being put into ITERATE and LEAVE; * **********************while ************* * ************ Syntax: java code [begin_label:] WHILE search_condition DO statement_list end while [end_label] instance: Java code DELIMITER $ drop procedure if exists pro_while $ create procedure pro_while (I INT) begin declare j int default 1; WHILE j <I DO SELECT j AS result; SET j = j + 1; END WHILE; END $ call: call pro_while (3); output: 1, 2 ************************** REPEAT ************ * ************* Syntax: java code [begin_label:] REPEAT statement_list UNTIL search_condition end repeat [end_label] instance: Java code DELIMITER $ drop procedure if exists pro_repeat $ create procedure pro_repeat (p1 INT) begin set @ X = 0; repeat select @ x as result; SET @ X = @ X + 1; UNTIL @ X> p1 end repeat; END $ call: call pro_repeat (2); output: 0, 1, 2 Note: first loop, then judge until @ X> p1 ends the loop