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.
public void doSomething(String [] strings) { for (int i = 0; i < strings.length; i--) { // Noncompliant String string = strings[i]; // ArrayIndexOutOfBoundsException when i reaches -1 //... }
public void doSomething(String [] strings) { for (int i = 0; i < strings.length; i++) { String string = strings[i]; //... }