loop_with_break_condition
Finds while true { if !c break; ... }, a loop whose condition is its first statement.
Category complexity, warn by default.
#import "Basic";
main :: () {
i := 0;
while true {
if i >= 10 break;
i += 1;
}
print("%\n", i);
}warning[loop_with_break_condition]: this loop leaves on its first statement; the test belongs in the `while`
--> example.jai:6:11
|
6 | while true {
| ^^^^
|
help: write `while i < 10` and drop the `if`
|
6 - while true {
7 - if i >= 10 break;
6 + while i < 10 {
|
= note: `loop_with_break_condition` is `warn` by default#import "Basic";
main :: () {
i := 0;
while i < 10 {
i += 1;
}
print("%\n", i);
}A while true (macros aside) whose body starts with an if without an else that only does an unlabelled break, with or without braces.