rules repository

G-4365

🆓
Warning

Never use unconditional CONTINUE or EXIT in a loop.

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

Non-Compliant Example

begin
   <<process_employees>>
   loop
      my_package.some_processing();

      continue process_employees;

      my_package.some_further_processing(); -- Dead code
   end loop process_employees;
end;
/
Issues
LineColumnMessage
616Never use unconditional CONTINUE a loop.

Compliant Solution - ★★★★★

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

References