posted 18 years ago
while (i++ < 3) //outer while
{
//System.out.println("with in outer while "+i);
do //inner do while.
System.out.print(j);
while (j++ < 3);
//System.out.println("with in outer while "+j);
}
In outer while, i value is used and then incremented. hence it runs for i 0,1,2. for these iterations, do while is executed.
Let us take one by one.
for i = 0.
point to note, in do while, statements are executed atleast once. So it prints 4 values 0,1,2,3. by the end of this do while execution, j becomes 4.
for i = 1.
again do while is executed and current j value 4 is printed. since the condition j++ <3 (4<3,j becomes 5) is not satisfied,it doesnot loop again.
for i = 2
do while executes once and prints 5 ,j becomes 6.
Keep Sop statements,such that you get to know the flow.