== Why is this an issue?

Labeled loops are useful, especially when the code is badly indented, to match the begin and end of each loop. When loops are nested, labeling them can improve the code's readability. This rule detects nested loops which do not have a start label.


=== Noncompliant code example

[source,sql]
----
BEGIN
  LOOP
    LOOP -- Noncompliant, this nested loop is not labeled
      EXIT;
    END LOOP;

    EXIT;
  END LOOP;

  FOR i IN 1..10  LOOP
    WHILE true LOOP -- Noncompliant, this nested loop has no start label
      EXIT;
    END LOOP nestedLoopLabel1;

    EXIT;
  END LOOP;

  WHILE true LOOP
    <<nestedLoopLabel2>>
    LOOP -- Compliant, but better with an end label
      EXIT;
    END LOOP;

    EXIT;
  END LOOP;
END;
/
----


=== Compliant solution

[source,sql]
----
BEGIN
  LOOP
    <<nestedLoopLabel0>>
    LOOP
      EXIT;
    END LOOP nestedLoopLabel0;

    EXIT;
  END LOOP;

  FOR i IN 1..10  LOOP
    <<nestedLoopLabel1>>
    WHILE true LOOP
      EXIT;
    END LOOP nestedLoopLabel1;

    EXIT;
  END LOOP;

  WHILE true LOOP
    <<nestedLoopLabel2>>
    LOOP
      EXIT;
    END LOOP nestedLoopLabel2;

    EXIT;
  END LOOP;
END;
/
----

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

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

=== Message

Add labels to this loop.


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