manual_index_counter
Finds a counter incremented in a for loop that always equals it_index.
Category complexity, warn by default.
#import "Basic";
show :: (names: [] string) {
n := 0;
for names {
print("% %\n", n, it);
n += 1;
}
}
main :: () {
show(.["ada", "grace"]);
}warning[manual_index_counter]: `n` always equals `it_index` of the loop that follows
--> example.jai:4:5
|
4 | n := 0;
| ^
|
help: use `it_index` instead of counting by hand
|
4 - n := 0;
7 - print("% %\n", n, it);
8 - n += 1;
6 + print("% %\n", it_index, it);
|
= note: `manual_index_counter` is `warn` by default#import "Basic";
show :: (names: [] string) {
for names {
print("% %\n", it_index, it);
}
}
main :: () {
show(.["ada", "grace"]);
}n := 0 right before a forward for (in a block, a case body or a #if branch), n += 1 at the end of the body (or defer n += 1), n unused after the loop.