This is modified code from the K & B book
The output is
i = 0, J = 0
Hello
i = 1, J = 0
Hello
i = 2, J = 0
Hello
i = 3, J = 0
Hello
i = 4, J = 0
Hello
i = 5, J = 0
Hello
i = 6, J = 0
Hello
i = 7, J = 0
Hello
i = 8, J = 0
Hello
i = 9, J = 0
Hello
Good-Bye
Is j being re-intialized to 0, or is the increment of the loop never being reached?
This is also from the k&B book
The declaration and initialization happens before anything else in a for loop. And whereas
the other two parts�the boolean test and the iteration expression�will run with
each iteration of the loop, the declaration and initialization happens just once, at the
very beginning.
[QUOTEIteration Expression
After each execution of the body of the for loop, the iteration expression is executed.
This part is where you get to say what you want to happen with each iteration of
the loop. Remember that it always happens after the loop body runs!
The book also states that the only time the iteration won't be avaluated is if there is a break, return or System.exit().
Could someone please explain why the code is behaving the way it is?