I never saw a tutorial or some lecture, which showed a classic for-loop witout the post-increment-order.
for (int i=0; i<array.length; i++) {}
If you use POST-increment, the variable "i" will be cached, before it will get incremented! But this makes no sense, because the command ends directly.
In my opinion, this makes more sense:
for (int i=0; i<array.length; ++i) {}
If you didn't understand until now, I go a bit further (sry for my english):
In the first loop:
- Cache the actual value of i. (note: no move between, so no reason to do this)
- Increment i
- Go ahead
In the second loop:
- Increment i directly
- Go ahead.
So the second loop is more performant for no quality loss. Any other opinions?