G-4380 Try to label your EXIT WHEN statements.

Minor

Maintainability

Reason

It's a good alternative for comments, especially for nested loops to name the loop to exit.

Example (bad)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
declare
   k_init_loop  constant simple_integer        := 0;
   k_increment  constant simple_integer        := 1;
   k_exit_value constant simple_integer        := 3;
   k_outer_text constant types.short_text_type := 'outer loop counter is ';
   k_inner_text constant types.short_text_type := ' inner loop counter is ';
   l_outerloop    pls_integer;
   l_innerloop    pls_integer;
begin
   l_outerloop := k_init_loop;
   <<outerloop>>
   loop
      l_innerloop := k_init_loop;
      l_outerloop := nvl(l_outerloop,k_init_loop) + k_increment;
      <<innerloop>>
      loop
         l_innerloop := nvl(l_innerloop, k_init_loop) + k_increment;
         sys.dbms_output.put_line(k_outer_text || l_outerloop ||
                                  k_inner_text || l_innerloop);

         exit when l_innerloop = k_exit_value;
      end loop innerloop;

      exit when l_innerloop = k_exit_value;
   end loop outerloop;
end;
/

Example (good)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
declare
   k_init_loop  constant simple_integer        := 0;
   k_increment  constant simple_integer        := 1;
   k_exit_value constant simple_integer        := 3;
   k_outer_text constant types.short_text_type := 'outer loop counter is ';
   k_inner_text constant types.short_text_type := ' inner loop counter is ';
   l_outerloop  pls_integer;
   l_innerloop    pls_integer;
begin
   l_outerloop := k_init_loop;
   <<outerloop>>
   loop
      l_innerloop := k_init_loop;
      l_outerloop := nvl(l_outerloop,k_init_loop) + k_increment;
      <<innerloop>>
      loop
         l_innerloop := nvl(l_innerloop, k_init_loop) + k_increment;
         sys.dbms_output.put_line(k_outer_text || l_outerloop ||
                                  k_inner_text || l_innerloop);

         exit outerloop when l_innerloop = k_exit_value;
      end loop innerloop;
   end loop outerloop;
end;
/