Originally posted by Patrick Punty:
class JMM110
{
public static void main (String[] args)
{
int j = 0;
do{
for (int i = 0; i++ < 2; )
{
System.out.print(i);
}
}while (j++ < 2);
}
Friends I didnt get the increment part of 'i'
as our 'for' syntax goes like this
for(A,B,C)
{
D
}
and its sequence of interpretting is ABDC untill B returns False.
So my question is it should printing 0 in place of 1
and the output should be 010101.
Please make my doubt clear.
My understanding is
first the control will come to for loop there it will initialize the variable i with 0 and then it will check 0<2 (which is true) so it will print 0 and then will increment the value so it will become 1.
Please correct me if I am wrong.
Hi Patrick,
Can you see that Increment statement in the condition block of for loop.
Every time condition is checked, i is incremented.
thus the output is 121212 instead of 010101
Hope this clears
[ October 09, 2005: Message edited by: Sandeep Chhabra ]
Regards<br />Sandy<br />[SCJP 5.0 - 75%]<br />[SCWCD 1.4 - 85%]<br />------------------<br />Tiger, Tiger burning bright,<br />Like a geek who works all night,<br />What new-fangled bit or byte,<br />Could ease the hacker's weary plight?