Page 1 of 1

About Question enthuware.ocajp.i.v7.2.1067 :

Posted: Wed Apr 22, 2015 10:26 am
by girish_v
{ continue ; }
This is incorrect as continue can be used only inside a 'for', 'while' or 'do while' loop

The same rule applies for this as well, correct?
block : { break block ; }
Block should also be used only inside a for, while, do while and switch.

Please explain

Re: About Question enthuware.ocajp.i.v7.2.1067 :

Posted: Wed Apr 22, 2015 7:54 pm
by admin
Did you read the explanation that is given with this option?

Re: About Question enthuware.ocajp.i.v7.2.1067 :

Posted: Thu Apr 23, 2015 4:57 am
by girish_v
yes, but hard to digest and understand the rationale. Why is this allowed - block:{break block;} and not this - block:{continue block;}

Re: About Question enthuware.ocajp.i.v7.2.1067 :

Posted: Thu Apr 23, 2015 10:13 am
by admin
Well, only Java language designers can give the reason for that :)

Re: About Question enthuware.ocajp.i.v7.2.1067 :

Posted: Sun May 03, 2015 8:37 pm
by davidsantiagomx
Indeed only the Java language designers could explain it, however I think they did following the common sense.

That is to say,

[break] breaks the iteration.
[continue] skips the current iteration and continue to the next.

In conclusion, it is not consistent [continue] can be used outside ['for', 'while' or 'do while' loop].

In other words, as omit the current iteration to continue to the next? ... If it is clear that there is no such iteration.
In contrast to 'break' that can simply exit.

greetings,
David

Re: About Question enthuware.ocajp.i.v7.2.1067 :

Posted: Sat Nov 14, 2015 1:52 pm
by toolforger
block: {continue/break block; } is invalid because block: is not a loop label, that's the reason why these are invalid; it does not matter whether you use a continue or a break.

Re: About Question enthuware.ocajp.i.v7.2.1067 :

Posted: Mon Feb 15, 2016 6:52 pm
by NickWoodward
toolforger wrote:block: {continue/break block; } is invalid because block: is not a loop label, that's the reason why these are invalid; it does not matter whether you use a continue or a break.
that's incorrect. block:{break block;} is valid. it's one of the answers.

and you can place a label on a code block {}

in my opinion:
label:{break label} makes sense, because you can break out of that code block.
label:{continue label} makes no sense because there is no loop to continue.

regards,

Nick

Re: About Question enthuware.ocajp.i.v7.2.1067 :

Posted: Tue Feb 16, 2016 2:52 am
by toolforger
You're right, I learned just yesterday that non-loop code blocks can have labels as well.

They can be targetted with break but not with continue. (Tested with Openjdk 1.7.0_95.)

Re: About Question enthuware.ocajp.i.v7.2.1067 :

Posted: Wed Feb 17, 2016 10:46 am
by NickWoodward
yeah, it took me a while to work out, had me confused!