About Question enthuware.ocajp.i.v7.2.1067 :
Moderator: admin
-
- Posts: 7
- Joined: Tue Apr 21, 2015 5:26 am
- Contact:
About Question enthuware.ocajp.i.v7.2.1067 :
{ 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
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
-
- Site Admin
- Posts: 10065
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1067 :
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.
-
- Posts: 7
- Joined: Tue Apr 21, 2015 5:26 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1067 :
yes, but hard to digest and understand the rationale. Why is this allowed - block:{break block;} and not this - block:{continue block;}
-
- Site Admin
- Posts: 10065
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1067 :
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.
-
- Posts: 1
- Joined: Sun May 03, 2015 7:01 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1067 :
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
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
-
- Posts: 38
- Joined: Fri Nov 13, 2015 4:40 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1067 :
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.
-
- Posts: 29
- Joined: Mon Mar 30, 2015 6:00 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1067 :
that's incorrect. block:{break block;} is valid. it's one of the answers.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.
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
-
- Posts: 38
- Joined: Fri Nov 13, 2015 4:40 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1067 :
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.)
They can be targetted with break but not with continue. (Tested with Openjdk 1.7.0_95.)
-
- Posts: 29
- Joined: Mon Mar 30, 2015 6:00 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1067 :
yeah, it took me a while to work out, had me confused!
Who is online
Users browsing this forum: Bing [Bot], Google [Bot] and 119 guests