Hi Anjali,
Let me seperate the two in different posts so tht one post doesnt become too long....
This is an example of a loop within a loop:
Remember that a do..while is considered as a single statement by the compiler!
Also remember that the do-while loop is executed ATLEAST once !!
so in the first Q....
the while(i++<3) condition is tested ...its true since i=0;
now value of i=1;
so it enters the loop...
it prints out the value of j which is 0; then the while condition of the do-while loop is checked while(j++<3)
the value of j used is 0 but after the condition is checked the value of j=1(POSTFIX NOTATION)
Since this returns true...execution flow goes back to the do statement..
prints out 1 chks do-while condition (1<3)--True..value of j=2
prints 2..chks condition(2<3) true--value of j=3
prints 3 chks condition(3<3)--FALSE..value of j=4--gets out of the do-while loop and goes to the initial while loop
Remember value of i=1...so (1<3)--true.new value of i=2..since its a do-while loop it will execute atleast once...
prints value of j=4 again chks the do-while condition (4<3)--False--value of j=5..breaks out of do-while...
initial while (2<3)--true--valueof i=3...performs the do-while
prints j=5 TOTAL OUTPUT 012345 chks do-while loop condition (5<3) false....goes to while loop condition (3<3) False...breaks out.....end
whew...hope didnt make it more confusing !!!
[ August 11, 2004: Message edited by: Murtuza Akhtari ]