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

Moderator: admin

Post Reply
girish_v
Posts: 7
Joined: Tue Apr 21, 2015 5:26 am
Contact:

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

Post by girish_v » Wed Apr 22, 2015 10:26 am

{ 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

admin
Site Admin
Posts: 8621
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin » Wed Apr 22, 2015 7:54 pm

Did you read the explanation that is given with this option?
If you like our products and services, please help us by posting your review here.

girish_v
Posts: 7
Joined: Tue Apr 21, 2015 5:26 am
Contact:

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

Post by girish_v » Thu Apr 23, 2015 4:57 am

yes, but hard to digest and understand the rationale. Why is this allowed - block:{break block;} and not this - block:{continue block;}

admin
Site Admin
Posts: 8621
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin » Thu Apr 23, 2015 10:13 am

Well, only Java language designers can give the reason for that :)
If you like our products and services, please help us by posting your review here.

davidsantiagomx
Posts: 1
Joined: Sun May 03, 2015 7:01 pm
Contact:

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

Post by davidsantiagomx » Sun May 03, 2015 8:37 pm

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

toolforger
Posts: 38
Joined: Fri Nov 13, 2015 4:40 am
Contact:

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

Post by toolforger » Sat Nov 14, 2015 1:52 pm

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.

NickWoodward
Posts: 29
Joined: Mon Mar 30, 2015 6:00 pm
Contact:

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

Post by NickWoodward » Mon Feb 15, 2016 6:52 pm

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

toolforger
Posts: 38
Joined: Fri Nov 13, 2015 4:40 am
Contact:

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

Post by toolforger » Tue Feb 16, 2016 2:52 am

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.)

NickWoodward
Posts: 29
Joined: Mon Mar 30, 2015 6:00 pm
Contact:

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

Post by NickWoodward » Wed Feb 17, 2016 10:46 am

yeah, it took me a while to work out, had me confused!

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests