Would ++i have been faster, execution-wise? I read somewhere way back (in Programming Gems I believe) that even in such cases, extra work must be done to make sure i can be incremented 1 after it's value is used in the expression (for i++ that is). It was based on c++, but I am wondering if i++ and ++i makes any difference here for java.
Leave speed of execution as your last priority. There is very little difference between ++i and i++ compared to the remainder of the loop, and I don't think there will be a difference in the body of the loops.
It is customary to use i++ when it is on its own. Since a for loop is a standardised construct, you will make maintenance much more difficult if you use uncoventional formats.
Joined: Jun 09, 2008
But there is a difference?
don't have much difference in maintainability. With the same results, the difference on performance would be my motivation to go with it.
I was just wondering about this, with the quality matrix aside of course. And I understand that design patterns and bottleneck analysis have a much greater impact on improving performance, but for the sake of adventure I tell you!
So...does it actually have a difference? Why is i++ the standard then I wonder.