PL/SQL Loop – Exit When

LOOP … EXIT WHEN syntax

LOOP
	--pl/sql statements
	EXIT WHEN condition;
	--pl/sql statements
END LOOP;

LOOP … EXIT WHEN example

DECLARE
  i NUMBER:=4;
BEGIN
DBMS_OUTPUT.PUT_LINE('Start');
LOOP
    i := i + 1;
    EXIT WHEN i > 7;
    DBMS_OUTPUT.PUT_LINE(' i: ' || i);
END LOOP;
DBMS_OUTPUT.PUT_LINE('End');
END;

Output

Start
 i: 5
 i: 6
 i: 7
End