The counter of a for
loop should be updated in the loop’s increment clause. The purpose of a for
loop is to iterate over
a range using a counter variable. It should not be used for other purposes, and alternative loops should be used in those cases.
If the counter is not updated, the loop will be infinite with a constant counter variable. If this is intentional, use a while
or
do
while
loop instead of a for
loop.
If the counter variable is updated within the loop’s body, try to move it to the increment clause. If this is impossible due to certain conditions,
replace the for
loop with a while
or do
while
loop.