In stored routines, which of the following demonstrates valid methods for working with loops?
A.
DECLARE i INT DEFAULT 0;
test loop: LOOP
SET i = i + 1;
IF i >= 5 THEN
LEAVE test_loop;
END IF;
END LOOP test_loop;
B.
DECLARE i INT DEFAULT 0;
WHILE i < 5 ITERATE
SET i = i + 1;
END WHILE;
C.
DECLARE i INT DEFAULT 0;
WHILE i < 5 DO
SET i = i + 1;
END WHILE;
D.
DECLARE i INT DEFAULT 0;
test loop: LOOP
SET i = i + 1;
IF i >= 5 THEN LEAVE;
END IF;
END LOOP test_loop;
Explanation:
B – WHILE..DO (NOT ITERATE).
D – LEAVE ONLY WORKS IF LABELLED.