Reassigning loop variables can lead to hard-to-find bugs, so I'm proposing (and currently working on) a rule that governs whether/how you are allowed to modify the loop variable.
This rule both applies to for and foreach loops:
for (int i=0; i < 10; i++) {
doSomethingWith(i);
i = 5; // not OK
}
for (int i=0; i < 10; i++) {
if (something(i)) {
i++; // OK
continue;
}
if (somethingElse(i)) {
i += 2; // OK
continue;
}
doSomethingWith(i);
}
I would add parameters to configure which, if any, operations the rule allows.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4