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