for loop stop conditions must be invariant (i.e. true at both the beginning and ending of every loop iteration). Ideally, this means that the stop condition is set to a local variable just before the loop begins.
Stop conditions that are not invariant are difficult to understand and maintain, and will likely lead to the introduction of errors in the future.
This rule tracks three types of non-invariant stop conditions:
for loop
for (var i = 0; i < 10; i++) {
...
i = i - 1; // Noncompliant
...
}
for (var i = 0; i < getMaximumNumber(); i++) {...}
int stopCondition = getMaximumNumber();
for (var i = 0; i < stopCondition; i++) {...}