Labeled loops are useful, especially when the code is badly indented, to match the begin and end of each loop. This rule verifies that loop start
and end labels match, when both are specified.
Noncompliant code example
BEGIN
LOOP
EXIT;
END LOOP; -- Compliant, this loop has no label at all
<<myLoopLabel1>>
LOOP
EXIT;
END LOOP; -- Compliant, this loop only has a start label
LOOP
EXIT;
END LOOP myLoopLabel2; -- Compliant, this loop only has an end label
<<myLoopLabel4>>
LOOP
EXIT;
END LOOP myLoopLabel5; -- Noncompliant, label mismatch
<<myLoopLabel6>>
<<myLoopLabel7>>
LOOP
EXIT;
END LOOP myLoopLabel7; -- Noncompliant, several start labels mismatch
END;
/
Compliant solution
BEGIN
LOOP
EXIT;
END LOOP;
<<myLoopLabel1>>
LOOP
EXIT;
END LOOP;
LOOP
EXIT;
END LOOP myLoopLabel2;
<<myLoopLabel4>>
LOOP
EXIT;
END LOOP myLoopLabel4;
<<myLoopLabel7>>
LOOP
EXIT;
END LOOP myLoopLabel7;
END;
/