rspec/rules/S2340/plsql/rule.adoc
2021-01-27 13:42:22 +01:00

37 lines
703 B
Plaintext

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
----
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
----
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;
/
----