Java Clarification

dighn

Lifer
Aug 12, 2001
22,820
4
81
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
 

slpaulson

Diamond Member
Jun 5, 2000
4,414
14
81
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.
 

6000SUX

Golden Member
May 8, 2005
1,504
0
0
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.
 

dighn

Lifer
Aug 12, 2001
22,820
4
81
Originally posted by: importdistributors
so if im gong to make a chart, do i start with both y and i equal to zero for the first loop?

depends on the chart