rspec/rules/S2340/plsql/rule.adoc
Fred Tingaud 16f6c0aecf
Inline adoc when include has no additional value (#1940)
Inline adoc files when they are included exactly once.

Also fix language tags because this inlining gives us better information
on what language the code is written in.
2023-05-25 14:18:12 +02:00

53 lines
941 B
Plaintext

== Why is this an issue?
Simple loops, of the form ``++LOOP ... END LOOP++``, behave by default as infinite ones, since they do not have a loop condition. They can often be replaced by other, safer, loop constructs.
=== Noncompliant code example
[source,sql]
----
SET SERVEROUTPUT ON
DECLARE
i PLS_INTEGER;
BEGIN
i := 1;
LOOP -- Noncompliant, an infinite loop by default and therefore dangerous
DBMS_OUTPUT.PUT_LINE('First loop i: ' || i);
i := i + 1;
EXIT WHEN i > 10;
END LOOP;
END;
/
----
=== Compliant solution
[source,sql]
----
SET SERVEROUTPUT ON
DECLARE
i PLS_INTEGER;
BEGIN
FOR i IN 1..10 LOOP -- Compliant, much safer equivalent alternative
DBMS_OUTPUT.PUT_LINE('Second loop i: ' || i);
END LOOP;
END;
/
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Give this loop an end condition.
endif::env-github,rspecator-view[]