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

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

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 »

{ 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: 10046
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin »

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 »

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: 10046
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin »

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 »

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 »

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 »

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 »

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 »

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 93 guests