Why is this an issue?
A for
loop with a counter that moves in the wrong direction, away from the stop condition, is not an infinite loop. Because of wraparound,
the loop will eventually reach its stop condition, but in doing so, it will probably run more times than anticipated, potentially causing unexpected
behavior.
How to fix it
Code examples
Noncompliant code example
for ($i = 0; $i < $length; $i--) { // Noncompliant
//...
}
Compliant solution
for ($i = 0; $i < $length; $i++) {
//...
}