Skip to content

Commit 0eeb731

Browse files
committed
Fix #49 - Added new rule G-4365: Never use unconditional CONTINUE or EXIT in a loop.
1 parent ff56239 commit 0eeb731

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# G-4365: Never use unconditional CONTINUE or EXIT in a loop.
2+
3+
!!! warning "Major"
4+
Maintainability, Testability
5+
6+
## Reason
7+
8+
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.
9+
10+
## Example (bad)
11+
12+
``` sql
13+
begin
14+
<<process_employees>>
15+
loop
16+
my_package.some_processing();
17+
18+
continue process_employees;
19+
20+
my_package.some_further_processing(); -- Dead code
21+
end loop process_employees;
22+
end;
23+
/
24+
```
25+
26+
## Example (good)
27+
28+
``` sql
29+
declare
30+
co_first_year constant pls_integer := 1900;
31+
begin
32+
<<process_employees>>
33+
loop
34+
my_package.some_processing();
35+
36+
continue process_employees when extract(year from sysdate) > co_first_year;
37+
38+
my_package.some_further_processing();
39+
end loop process_employees;
40+
end;
41+
/
42+
```

docs/9-appendix/appendix.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ n/a | 4325 | Never reuse labels in inner scopes. | Major | | | &#10008; | | &
7878
42 | 4340 | Always use a NUMERIC FOR loop to process a dense array. | Minor | | | &#10008; | | | | |
7979
43 | 4350 | Always use 1 as lower and COUNT() as upper bound when looping through a dense array. | Major | | | | | &#10008; | | |
8080
44 | 4360 | Always use a WHILE loop to process a loose array. | Minor | | &#10008; | | | | | |
81+
n/a | 4365 | Never use unconditional CONTINUE or EXIT in a loop. | Major | | | &#10008; | | | | | &#10008;
8182
45 | 4370 | Avoid using EXIT to stop loop processing unless you are in a basic loop. | Major | | | &#10008; | | | | |
8283
46 | 4375 | Always use EXIT WHEN instead of an IF statement to exit from a loop. | Minor | | | &#10008; | | | | |
8384
47 | 4380 | Try to label your EXIT WHEN statements. | Minor | | | &#10008; | | | | |

0 commit comments

Comments
 (0)