Question about some book

Moderator: admin

Post Reply
flex567
Posts: 84
Joined: Mon Apr 02, 2018 8:40 am
Contact:

Question about some book

Post by flex567 » Thu May 17, 2018 12:57 am

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?
Capture.PNG
Capture.PNG (38.15 KiB) Viewed 329 times

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

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

Post by admin » Thu May 17, 2018 1:54 am

Well, three things -
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;
       }
   }
} 
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.
If you like our products and services, please help us by posting your review here.

flex567
Posts: 84
Joined: Mon Apr 02, 2018 8:40 am
Contact:

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

Post by flex567 » Thu May 17, 2018 3:53 pm

But it is explained clearly in another question 2.1193.
I couldn't find the question enthuware.ocajp.i.v7.2.1193.

Are you refering to some other question?

From the book:
The 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.
"Without a label parameter, the break statement will terminate the nearest inner loop it is
currently in the process of executing." -> "If" statement doesn't count as the inner loop?

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

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

Post by admin » Thu May 17, 2018 7:59 pm

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 :

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
test.png (36.55 KiB) Viewed 305 times
If you like our products and services, please help us by posting your review here.

flex567
Posts: 84
Joined: Mon Apr 02, 2018 8:40 am
Contact:

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

Post by flex567 » Fri May 18, 2018 4:57 pm

I only searched with Ctrl+Q.

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

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

Post by admin » Fri May 18, 2018 10:31 pm

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.
If you like our products and services, please help us by posting your review here.

flex567
Posts: 84
Joined: Mon Apr 02, 2018 8:40 am
Contact:

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

Post by flex567 » Sat May 19, 2018 5:10 am

yes I entered entered enthuware.ocajp.i.v7.2.1093

Post Reply

Who is online

Users browsing this forum: No registered users and 13 guests