*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Problem with labeled break 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 "Problem with labeled break" Watch "Problem with labeled break" New topic
Author

Problem with labeled break

Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

Question from pgjc - mock exam, the link to this in the SCJP_Links of this forum.


This compilation failed. I couldn't find the problem... Thanks in Advanced!


|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9321
    
  17

You cannot put a label on a declaration statement. In your code label l2 is on the declaration line of j which is not allowed...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

Ankit Garg wrote:You cannot put a label on a declaration statement. In your code label l2 is on the declaration line of j which is not allowed...


Thanks for this quick reply. But if we change the declaration line, the program flow will change. Then how to modify this?

Thanks in Advanced!
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 19073
    
  40

Abimaran Kugathasan wrote:
Thanks for this quick reply. But if we change the declaration line, the program flow will change. Then how to modify this?


If the program doesn't compile, it doesn't run. And if the program doesn't run, what "program flow" are you trying to preserve? Or are you referring to the program flow, of a working version, before the change that caused this compile error?

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

Henry Wong wrote:
If the program doesn't compile, it doesn't run. And if the program doesn't run, what "program flow" are you trying to preserve? Or are you referring to the program flow, of a working version, before the change that caused this compile error?

Henry


Yea Correct! We need to think in a different style. I mean the flow(execution) of the program, not the versions!

Thanks for correcting me!
Samrat Debroy
Greenhorn

Joined: Oct 23, 2009
Posts: 13
I think nothing much to "think in a different style". Correct me if I am wrong.



This has the same effect. Lemme know if this retain your "program flow".
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

Can't we label a statement?
Lokesh Duseja
Greenhorn

Joined: Jul 03, 2010
Posts: 5
Yes you can!!

You can label any statement under the sun

But using that label for "break or continue" is a problem...To use them with break or continue, it should be exactly above the loop, with no other statement in between...

Sun Certified Java Programmer -6.0
IBM Websphere MQ Series System Administrator - 5.3
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with labeled break