Skip to content

G-4365: Never use unconditional CONTINUE or EXIT in a loop.

Major

Maintainability, Testability

Reason

An unconditional continue is either redundant (a continue as the last statement before the end of the loop) or causes dead code. An unconditional exit causes no looping and may cause dead code as well. If continue or exit is needed, it should always have a condition.

Example (bad)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
begin
   <<process_employees>>
   loop
      my_package.some_processing();

      continue process_employees;

      my_package.some_further_processing(); -- Dead code
   end loop process_employees;
end;
/

Example (good)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
declare
   co_first_year constant pls_integer := 1900;
begin
   <<process_employees>>
   loop
      my_package.some_processing();

      continue process_employees when extract(year from sysdate) > co_first_year;

      my_package.some_further_processing();
   end loop process_employees;
end;
/