G-4340: Always use a NUMERIC FOR loop to process a dense array.

Minor

Maintainability

Reason

It is easier for the reader to see that the complete array is processed.

Since an exit statement is similar to a goto statement, it should be avoided whenever possible.

Example (bad)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
declare
   type t_employee_type is varray(10) of employee.employee_id%type;
   t_employee   t_employee_type;
   k_himuro     constant integer := 118;
   k_livingston constant integer := 177;
   k_min_value  constant simple_integer := 1;
   k_increment  constant simple_integer := 1;
   i pls_integer;
begin
   t_employee := t_employee_type(k_himuro, k_livingston);
   i          := k_min_value;

   <<process_employees>>
   loop
      exit process_employees when i > t_employee.count();
      sys.dbms_output.put_line(t_employee(i));
      i := i + k_increment;
   end loop process_employees;
end;
/

Example (good)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
declare
   type t_employee_type is varray(10) of employee.employee_id%type;
   t_employee   t_employee_type;
   k_himuro     constant integer := 118;
   k_livingston constant integer := 177;
begin
   t_employee := t_employee_type(k_himuro, k_livingston);

   <<process_employees>>
   for i in 1..t_employee.count()
   loop
     sys.dbms_output.put_line(t_employee(i));
   end loop process_employees;
end;
/