This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
So switch(1) which results in calling of case 1: continue label2 - will result in execution of while condition again NOT the do one so ++j means j=1;
Then the do condition... i=2 k=h+i+j = 0+2+1 =3.
now case 3: break label2; -- break out of the while loop and to the next iteration of for loop.
h=1... I think you should figure out from here what happens.
Hope this will help. Regards, Joshua
SCJP,SCWCD, Into ATG now!
Joined: Jan 05, 2006
I have figured out where I was going wrong and this time of my hand calculation got the correct answer with the help of wise and Joshua. Thank you very much. I wouldn�t have figured it out without your help. Thanks again for your time. Great work.
These labels can be tricky, especially in a do-while loop. Where does the "continue" jump in this example?
It's tempting to say: "Well, it jumps to the label, and the next line is do, followed by if (i==2)." But that's wrong. The continue jumps to the while and the i is incremented. If it wouldn't, the example would be an endless loop. But it isn't, it will print out
In the example the same would happen if you said continue; (without label).