This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I'm trying to understand your question a little better. It sounds like you wanted i to have the value of 1 at the start of your loop, so you used
for ( i = 0; i < 100; ++i )
for ( i = 0; i < 100; i++ ).
Do I understand that part correctly?
Like Louis said, the difference between i++ and ++i only shows up if you're combining that increment with another operation. In his example the other operation is an assignment.
I think what Katrina was saying is that in a for loop, you're not combining the increment with another operation, so you don't see the difference between i++ and ++i. (Please correct me, Katrina, if I'm off here!)
Each time through the loop, your code does something like this (here in pseudocode):
// first it checks if it should go through the loop again if ( i < 100 )
// if so, it does whatever you want to do in the loop
// then it increments i i++ ;
// after that, it would check again whether i is less than 100 and so on
The increment is "on it's own line" as Katrina said. It's not compounded with another operation, so it wouldn't make a difference if it was written i++ or ++i.
Remember what you read in the assignment page about loops? How the equivalent of a for loop can be written with a while loop like this:
Take a look at a simple "while loop":
The "for loop" shorthand for this is:
Maybe that makes sense?
You might want to play around with some code, since that's the most fun...
...like, what happens when you write this?
int someNumber = 1 ; System.out.println( "someNumber is " + someNumber ) ; System.out.println( "someNumber is " + someNumber++ ) ; System.out.println( "someNumber is " + ++someNumber ) ;
In the last two examples, the increment is compounded with printing out the value of someNumber.