A for
loop with a counter moving away from the end of the specified range is likely a programming mistake.
If the intention is to iterate over the specified range, this differs from what the loop does because the counter moves in the wrong direction.
If the intention is to have an infinite loop or a loop terminated only by a break statement, there are two problems:
- The loop condition is not infinite because the counter variable will eventually overflow and fulfill the condition. This can take a long time,
depending on the data type of the counter.
- An infinite loop terminated by a
break
statement should be implemented using a while
or do
while
loop to make the developer’s intention clear to the reader.