This week's giveaway is in the Spring forum. We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line! See this thread for details.

What will the following program print? class Test { public static void main(String args[]) { int i=0, j=0; X1: for(i = 0; i < 3; i++)<br /> {<br /> X2: for(j = 3; j > 0; j--) { if(i < j) continue X1; else break X2;

} } System.out.println(i+" "+j); } } Answer is : 3 3 If i<3, then how is it possible for 'i' to get the value 3. And the same case is with 'j' please explain

1 st iteration i== 0 j == 3 thus i < j true skip inner i++ @ outer 2nd iteration i== 1 j == 3 thus i < j true skip inner i++ @ outer 3rd iteration i== 2 j == 3 thus i < j true skip inner i++ @ outer 4th iteration i== 3 j == 3 thus i < j false skip(break) inner because of else path . outer ends because 3<3 false then you fall out and print i == 3 and j == 3 ( becuase of inner j=3 ! ) pencil & paper thats what u will be given and use them !

------------------ Have a nice day, Unless you've made other plans. [This message has been edited by ersin eser (edited December 30, 2001).]

Originally posted by ersin eser: 1 st iteration i== 0 j == 3 thus i < j true skip inner i++ @ outer 2nd iteration i== 1 j == 3 thus i < j true skip inner i++ @ outer 3rd iteration i== 2 j == 3 thus i < j true skip inner i++ @ outer 4th iteration i== 3 j == 3 thus i < j false skip(break) inner because of else path . outer ends because 3<3 false then you fall out and print i == 3 and j == 3 ( becuase of inner j=3 ! ) pencil & paper thats what u will be given and use them !

I believe your 4th explanation here is not correct. When i = 3, The X2 block ( i < j section) will not even be evaluated (since i is not less than 3 ). However since the local variable i is set to 3 it will be 3 when it is printed. With j, the variable never gets set to anything less than 3 since i is always evealuating to be less than 3 and thus the continue X1 gets executed. Maybe I'm wrong, but I think that's how it's working.