2023-05-03 11:06:20 +02:00
== Why is this an issue?
2021-01-27 13:42:22 +01:00
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.
2020-06-30 12:48:07 +02:00
2023-05-03 11:06:20 +02:00
=== Noncompliant code example
2020-06-30 12:48:07 +02:00
2022-02-04 17:28:24 +01:00
[source,sql]
2020-06-30 12:48:07 +02:00
----
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;
/
----
2023-05-03 11:06:20 +02:00
=== Compliant solution
2020-06-30 12:48:07 +02:00
2022-02-04 17:28:24 +01:00
[source,sql]
2020-06-30 12:48:07 +02:00
----
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;
/
----
2021-09-20 15:38:42 +02:00
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
2023-05-25 14:18:12 +02:00
=== Message
Give this loop an end condition.
2021-09-20 15:38:42 +02:00
endif::env-github,rspecator-view[]