Question about some book
Moderator: admin
-
- Posts: 202
- Joined: Mon Apr 02, 2018 8:40 am
- Contact:
Question about some book
In the book for the exam it is explicitly mentioned that if statement don't support break, but you don't mention that in the answer nor in that post.
I don't know who is right you or the book?
I don't know who is right you or the book?
-
- Site Admin
- Posts: 10036
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1057 :
Well, three things -
1. what happened when you compiled the code with a break in if?
Here is the code that compiles fine:
2. The table in the book is talking about breaking an if condition, (and not about breaking from an if contained in a labelled loop) which of course is not possible but you should check with the author.
3. This point is not covered in this question because the this question is about something else. But it is explained clearly in another question 2.1193. Each question will not cover all the points (because that is not the objective of the questions), but if you go through all the questions, you can be assured that all the points will be covered.
HTH,
Paul.
1. what happened when you compiled the code with a break in if?
Here is the code that compiles fine:
Code: Select all
void crazyLoop(){
int c = 0;
JACK: while (c < 8){
System.out.println(c);
if (c > 3) {
break JACK;
}
}
}
3. This point is not covered in this question because the this question is about something else. But it is explained clearly in another question 2.1193. Each question will not cover all the points (because that is not the objective of the questions), but if you go through all the questions, you can be assured that all the points will be covered.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 202
- Joined: Mon Apr 02, 2018 8:40 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1057 :
I couldn't find the question enthuware.ocajp.i.v7.2.1193.But it is explained clearly in another question 2.1193.
Are you refering to some other question?
From the book:
"Without a label parameter, the break statement will terminate the nearest inner loop it isThe break statement can take an optional label parameter.
Without a label parameter, the break statement will terminate the nearest inner loop it is
currently in the process of executing. The optional label parameter allows us to break out
of a higher level outer loop.
currently in the process of executing." -> "If" statement doesn't count as the inner loop?
-
- Site Admin
- Posts: 10036
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1057 :
1. How did you search? See attached image. This question is there in v7 as well as in v8.
2. You really need to ask the author of the book regarding statements from the book. But yes, "if" is not a loop. I think the book must have discussed this while talking about loops. So an unlabelled break in an if block is not valid unless the if statement is within a loop.
But a labelled break from an if block is possible. The following code compiles and runs fine :
2. You really need to ask the author of the book regarding statements from the book. But yes, "if" is not a loop. I think the book must have discussed this while talking about loops. So an unlabelled break in an if block is not valid unless the if statement is within a loop.
But a labelled break from an if block is possible. The following code compiles and runs fine :
Code: Select all
public static void main(String[] args){
int i = 0;
LABEL: if(true){
System.out.println("break label");
i = 3;
if( i == 3){
break LABEL; //this is valid
}
System.out.println("not executed");
}
}
- Attachments
-
- test.png (36.55 KiB) Viewed 1901 times
If you like our products and services, please help us by posting your review here.
-
- Posts: 202
- Joined: Mon Apr 02, 2018 8:40 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1057 :
I only searched with Ctrl+Q.
-
- Site Admin
- Posts: 10036
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1057 :
It opens with Ctrl Q as well. You need to enter just 2.1193
You probably entered enthuware.ocajp.i.v7.2.1093 instead of enthuware.ocajp.i.v8.2.1093.
You probably entered enthuware.ocajp.i.v7.2.1093 instead of enthuware.ocajp.i.v8.2.1093.
If you like our products and services, please help us by posting your review here.
-
- Posts: 202
- Joined: Mon Apr 02, 2018 8:40 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1057 :
yes I entered entered enthuware.ocajp.i.v7.2.1093
Who is online
Users browsing this forum: Bing [Bot], Google [Bot] and 27 guests