Forums Register Login

break using label

+Pie Number of slices to send: Send

out:
?0
1
?1
2
2
?2
3
When x is 1,it get "break label" in switch().
Next,I think it should be perform "x++".
But computer shows it performs "System.out.println("?" + x);".
why?
+Pie Number of slices to send: Send
From the JLS, §14.14 The break Statement:


A break statement with label Identifier attempts to transfer control to the enclosing labeled statement (�14.7) that has the same Identifier as its label; this statement, which is called the break target, then immediately completes normally.


So, you're right when you say that the target is the do loop. However, that do loop ends abruptly and we continue with the next iteration of the outer loop.
That's why we end up flowing directly into the next iteration of the outer loop.
I hope that helps,
Corey
+Pie Number of slices to send: Send
Thx, Corey!
I got it.
"break label" causes do Loop to be abandoned.
+Pie Number of slices to send: Send
hi val, x++ will get executed when you have continue there instead of break.,break statement takes you out of the loop,higher up to the next label which is in higher order., i have changed ur code little bit here ... see this...HTH
+Pie Number of slices to send: Send
Thx,srinivas!
Good Job!
To do a great right, do a little wrong - shakepeare. twisted little ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1066 times.
Similar Threads
Dan's Exam on Flow control
Help with loop label problem
Can label be placed before switch?
what is the diffrence b/W i and i++ and explain inner loops with conditions
pls consider this program i don't know how h value is incremented in Label1:
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 07:47:16.