• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with labeled break

 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Ankit Garg
Sheriff
Posts: 9528
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21490
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can't we label a statement?
 
Lokesh Duseja
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic