views:

411

answers:

0

Possible Duplicates:
Difference between i++ and ++i in a loop?
java for loop pre-increment vs post-increment

When using the standard for loop, how does the compiler treat the incrementing of the for loop variables?

For example,

for(int i = 0; i < 5; i++)
       {
            System.out.println("i is : " + i);           
       }

Would print out the following

i is : 0
i is : 1
i is : 2
i is : 3
i is : 4

However, if I alter the incremting to prefix incrementing, the output is the same

for(int i = 0; i < 5; ++i)
       {
            System.out.println("i is : " + i);           
       }

Does the compiler process the loop in sequential order? such as : for(initialisation; condition; incrementing). Therefore, the incrementing part would only happen after the initialisation and conditions, meaning a prefix or postfix incrementing operator behave the same way?

Bit of a nonsense question, but I'm curious as to how the compiler treats loops