LOOP
EXIT WHEN boolan_expression; -- terminate loop statement if boolan_expression is true
EXIT; -- terminate loop statement immediately
CONTINUE; -- go to next iteration
CONTINUE WHEN …
END LOOP;
FOR num IN 1 .. 5 LOOP
FOR mun IN REVERSE 1 .. num LOOP
…
END LOOP;
END LOOP;
WHILE boolean_expression LOOP
…
END LOOP;
Leaving a loop
The processing of a loop can be left prematurely with the exit statement:
begin
for i in 1 .. 5 loop
dbms_output.put_line(i);
if i = 3 then
exit;
end if;
end loop;
end;
With exit when, a loop can be left conditionally:
begin
for i in 1 .. 5 loop
dbms_output.put_line(i);
exit when i = 4;
end loop;
end;
Go directly to next iteration
The continue statement skips the rest of the loop body and goes directly to the next iteration of the loop:
begin
for i in 1 .. 10 loop
dbms_output.put(i || ' ');
continue when i > 5;
dbms_output.put_line('');
end loop;
dbms_output.put_line('');
end;
/