Yes. It is bad practice. It will compile and run just fine, but in answer to your question, it is bad practice.
If you want to manually update your iterator, use a while
loop.
Anything you can do with a for
loop can also be done with a while
loop. The choice in what loop to actually implement is a matter of readability. In for
loops, people expect the iterator to be updated in the update statement and only in the update statement.
If you can't figure out how to rewrite your loop so your iterator is updated only in the update statement, consider something like this:
for(int i=0; i<someValue; ++i /*i also updated at line 18*/)
Just as an example. This is still worse than rewriting the code so it's not updated at line 18 (or whatever line) but far better than updating it at line 18 and not leaving the comment here in the update statement.
Alternatively, per comments on this answer, try this:
for(int i=0; i<someValue; /*see body*/) {
//do stuff
//update i
//do stuff
}
Now in this case, your update statement is completely empty, so even without the /*see body*/
comment, anyone maintaining your code already know that i
must be modified somewhere within the body. And the ++i
behavior from the update statement can be recreated simply by adding ++i
as the last line of the for
loop.