The continue pushes you to the end of the do-loop and then you go to the label.
Originally posted by suresh kamsa:
case 3: continue label3;
can you be more specific please. It will not go to label3? still variable i will be incremented by 1 so the value should become 2 previous values j is 1 and k is 1, which is i+j+k = 4.
How come it is 5?
A break statement with a label will transfer control outside of the enclosing statement with the matching label. Furthermore, the enclosing statements complete abruptly. In the case of a do-while loop, the boolean expression that controls the loop is not evaluated as control transfers out of the loop. However, if the break statement had been executed inside a try-catch block, then the finally clause would have been processed. The first iteration of this code example executes the case statement with the value 3. As a result, the statement "break label3" is executed causing the inner most loop to complete abruptly and control to be transferred out of the inner most loop to the second nested loop. The boolean expression of the second loop is evaluted and variable j is incremented as a side effect. The boolean expression evalutes as true and a second iteration begins. Variable j is incremented again at the top of the loop and varible i is incremented at the top of the inner most loop. The switch expression evaluates as six. A continue statement without a label will cause the current iteration of the enclosing loop to end and the next iteration to begin. As a result, the boolean expression that controls the loop is evaluated as the next iteration begins. Similarly, a continue statement that has a label transfers control to the next iteration of the enclosing loop that has the same label. If the continue statement causes control to break out of a nested loop to transfer control to an outer loop with a matching label, then execution of the nested loop is completed abruptly as control transfers to the outer loop. Furthermore, the boolean expression that controls the nested loop is not evaluated as control is abruptly transferred to the labeled outer loop.