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

[source,sql]
----
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

[source,sql]
----
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;
/
----

ifdef::env-github,rspecator-view[]

'''
== Implementation Specification
(visible only on this page)

include::message.adoc[]

endif::env-github,rspecator-view[]
