Labeled loops are useful, especially when the code is badly indented, to match the begin and end of each loop. Within a labeled loop, the code’s
maintainability is increased by explicitly providing the loop’s label in every EXIT
statement. Indeed, if a nested loop is added
afterwards, it is clear which loop has to be exited.
Noncompliant code example
BEGIN
<<myLoopLabel1>>
LOOP
EXIT; -- Noncompliant, the loop label is missing
END LOOP myLoopLabel1;
LOOP
EXIT; -- Compliant, this EXIT is not in a labeled loop
END LOOP;
END;
/
Compliant solution
BEGIN
<<myLoopLabel1>>
LOOP
EXIT myLoopLabel1;
END LOOP myLoopLabel1;
LOOP
EXIT;
END LOOP;
END;
/