• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Java Clarification

c

i++ and ++i both increments i, the difference is that (++i) evaluates to value of i after the increment and (i++) evalutes to the value before the icnremnet

hwoever in a loop it doesn't really matter
 
I really haven't played around with it much, but basically i++ should increment a variable after using, while ++i will increment before it is used.

For example if i = 10, System.out.println(++i); would print out 11, while System.out.println(i++) would print out 10. In both cases i would be 11 after the print statement.

At least I think that is correct. I pretty much never write code that it would make a difference.
 
You must be very lazy not to run a test for yourself, which would let you figure out the reason for the answer if you didn't already know.

The loop runs eleven times, due to the <= in the termination expression. In this case there is no difference between ++i and i++ in the increment expression.
 
Back
Top