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

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

Moderator: admin

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

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

Post by admin »

Yes, correct.
If you like our products and services, please help us by posting your review here.

DazedTurtle
Posts: 26
Joined: Wed Oct 02, 2019 1:42 pm
Contact:

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

Post by DazedTurtle »

Okay, I understand the question just fine, and I got it right, but I like reading the explanations just in case I come across a small detail I was unaware of, and I can't understand what's being said here:
So, only one iteration (that too not full) is performed for the inner loop.
The bolded bit makes no sense to me. I don't know if there's a word missing or if there's a grammar error or if my brain's just having issues parsing it, but I can't figure out what you mean.

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

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

Post by admin »

The only iteration that occurs for this loop is not executed fully because of if (x == 0) { continue loop; } part. The last statement of the inner loop is not executed.
If you like our products and services, please help us by posting your review here.

nerdchieftain
Posts: 5
Joined: Sun Mar 08, 2020 3:55 pm
Contact:

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

Post by nerdchieftain »

The code

Code: Select all

loop:
and

Code: Select all

continue loop;
is unfamiliar to me.

I assume this is a label or the language now allows naming a loop (and here the name used is loop). I cannot figure out what to call this language feature in order to search for it and learn more. What is it?

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

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

Post by admin »

Yes, loop is a label. continue <label>; can be found under labelled break and continue section.
https://docs.oracle.com/javase/tutorial ... ranch.html
If you like our products and services, please help us by posting your review here.

Denyo1986
Posts: 38
Joined: Thu Jan 07, 2021 2:47 am
Contact:

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

Post by Denyo1986 »

In another question (dont remember the number unfortunately) there was a similar case with break labels. In that question it said that the label needs to be in the same context as the break/continue statement, otherwise it becomes unreachable / not known to the break/continue statement.
If my memory is correct, the example was very very similar. And I would have thought that here, in this question, the continue loop; statement does not see the loop label as it is outside of another FOR loop.

Could you please comment on this? Maybe you know which question I mean? It would be great if you could explain the difference or a clear explanation in what context (i.e. how far) labels are known.

Thanks a lot for your hel

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

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

Post by admin »

You might have seen something similar in the explanation to question 2.1281. But it is not the same. That explanation is talking about the location of break and continue with labels.
If you use a break/continue with a label, then that label must be on a block that is enclosing the break/continue statement.

You can apply a label to any statement in general. There is no restriction. But you can't just break to any label. (otherwise, that would amount to a goto statement, which, of course, java does not have.)
If you like our products and services, please help us by posting your review here.

Denyo1986
Posts: 38
Joined: Thu Jan 07, 2021 2:47 am
Contact:

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

Post by Denyo1986 »

OK, thanks for the explanation. The question you refer to is not the one I meant. If I find it again, I will let you know.

But how is it defined, what a block is, where it starts and where it ends??
Cannot find clear information about this.

Here, if I remember correctly, the break statement was in a loop. The label before the for loop. Seems to me like two different blocks. I am missing clear borders/clear understanding where this starts and ends.

Can you point me in the right direction, please?

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

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

Post by admin »

You may go through section 14.15 The break Statement of JLS 11 (or the section with the same title in JLS 8).

Observe this statement from this section:
A break statement must refer to a label within the immediately enclosing method, constructor, or initializer. There are no non-local jumps. If no labeled statement with Identifier as its label in the immediately enclosing method, constructor, or initializer contains the break statement, a compile-time error occurs.
You may check out the details of the continue statement as well in the same chapter.
If you like our products and services, please help us by posting your review here.

Denyo1986
Posts: 38
Joined: Thu Jan 07, 2021 2:47 am
Contact:

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

Post by Denyo1986 »

http://enthuware.com/forum/viewtopic.php?f=2&t=2236

This is the question I was referring to. And now I understand the difference. Because JILL is not followed by brackets {}, its scope is only the following statement (the println()) which doesnt make sense as you can never actually break to this label. So in order to make this work, one would have to add brackets after JILL and include the if and else part).

Post Reply

Who is online

Users browsing this forum: No registered users and 67 guests