G-4380
🆓Warning
Try to label your EXIT WHEN statements.
Reason
It's a good alternative for comments, especially for nested loops to name the loop to exit.
Example
Non-Compliant Example
declare co_init_loop constant simple_integer := 0; co_increment constant simple_integer := 1; co_exit_value constant simple_integer := 3; co_outer_text constant types_up.short_text_type := 'Outer Loop counter is '; co_inner_text constant types_up.short_text_type := ' Inner Loop counter is '; l_outerlp pls_integer; l_innerlp pls_integer; begin l_outerlp := co_init_loop; <<outerloop>> loop l_innerlp := co_init_loop; l_outerlp := nvl(l_outerlp,co_init_loop) + co_increment; <<innerloop>> loop l_innerlp := nvl(l_innerlp,co_init_loop) + co_increment; sys.dbms_output.put_line(co_outer_text || l_outerlp || co_inner_text || l_innerlp); exit when l_innerlp = co_exit_value; end loop innerloop; exit when l_innerlp = co_exit_value; end loop outerloop; end; /
Issues
Line | Column | Message |
---|---|---|
23 | 10 | |
26 | 7 |
★★★★★
Compliant Solution -
declare co_init_loop constant simple_integer := 0; co_increment constant simple_integer := 1; co_exit_value constant simple_integer := 3; co_outer_text constant types_up.short_text_type := 'Outer Loop counter is '; co_inner_text constant types_up.short_text_type := ' Inner Loop counter is '; l_outerlp pls_integer; l_innerlp pls_integer; begin l_outerlp := co_init_loop; <<outerloop>> loop l_innerlp := co_init_loop; l_outerlp := nvl(l_outerlp,co_init_loop) + co_increment; <<innerloop>> loop l_innerlp := nvl(l_innerlp,co_init_loop) + co_increment; sys.dbms_output.put_line(co_outer_text || l_outerlp || co_inner_text || l_innerlp); exit outerloop when l_innerlp = co_exit_value; end loop innerloop; end loop outerloop; end; /
References
- same as Trivadis G-4380
- same as plsql:LoopUnlabeledExitCheck