File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes break using label Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "break using label" Watch "break using label" New topic
Author

break using label

Val Lee
Ranch Hand

Joined: Nov 27, 2001
Posts: 41

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?


Val SCJP2 1.2<br />====>SCJD
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
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


SCJP Tipline, etc.
Val Lee
Ranch Hand

Joined: Nov 27, 2001
Posts: 41
Thx, Corey!
I got it.
"break label" causes do Loop to be abandoned.
srinivas bolloju
Ranch Hand

Joined: Jan 23, 2001
Posts: 112
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


please use the [code][/code] tags when showing code. visit <a href="http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=ubb_code_page" target="_blank" rel="nofollow">http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=ubb_code_page</a> ,for more details
Val Lee
Ranch Hand

Joined: Nov 27, 2001
Posts: 41
Thx,srinivas!
Good Job!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: break using label