rules repository

G-4320

🆓
Warning

Always label your loops.

Reason

It's a good alternative for comments to indicate the start and end of a named loop processing.

Example

Non-Compliant Example

declare
   i pls_integer;
begin
   i := 1;
   while (i <= 10)
   loop
      i := i + 1;
   end loop;

   loop
      exit when true;
   end loop;

   for i in 1..10
   loop
      sys.dbms_output.put_line(i);
   end loop;

   for r_employee in (select last_name from employees)
   loop
      sys.dbms_output.put_line(r_employee.last_name);
   end loop;
end;
/
Issues
LineColumnMessage
54Missing start label in while loop statement.
88Missing end label in while loop statement.
104Missing start label in basic loop statement.
128Missing end label in basic loop statement.
144Missing start label in for loop statement.
178Missing end label in for loop statement.
194Missing start label in cursor for loop statement.
228Missing end label of cursor for loop statement.

Compliant Solution - ★★★★★

declare
   i pls_integer := 0;
begin
   <<while_loop>>
   while (i <= 10)
   loop
      i := i + 1;
   end loop while_loop;

   <<basic_loop>>
   loop
      exit when true;
   end loop basic_loop;

   <<for_loop>>
   for i in 1..10
   loop
      sys.dbms_output.put_line(i);
   end loop for_loop;

   <<process_employees>>
   for r_employee in (select last_name from employees)
   loop
      sys.dbms_output.put_line(r_employee.last_name);
   end loop process_employees;
end;
/

References