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

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

Moderator: admin

Post Reply
Zoryanat
Posts: 20
Joined: Tue Aug 27, 2013 3:16 am
Contact:

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

Post by Zoryanat »

It says in answers that you cannot have something like
while (int k=5; k<7) ....

what about having while (k<7) - is that legal? I mean, if k was instantiated previous to while loop, then this expression should return true / false which is OK for while loop.

?

Thanks a mill!
Regards
Zoryana

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

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

Post by admin »

Yes, while(k<7) is fine.

HTH,
Paul.

Zoryanat
Posts: 20
Joined: Tue Aug 27, 2013 3:16 am
Contact:

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

Post by Zoryanat »

Thanks, Paul.

codecodecode67
Posts: 14
Joined: Sun Dec 06, 2015 2:15 pm
Contact:

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

Post by codecodecode67 »

Hi,

If the while statement in the question is made to be (int k=5;k<7;) instead of (int k=5;k<7), it will be a bit more confusing. I for example somehow disregarded it's a while loop and thought it was an illegal for-loop (missing the last semicolon).

In the answer (int k=5;k<7;) is used and not (int k=5;k<7) as an example for an invalid while loop. I think this should be extended to the question itself to make it harder.

:)

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

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

Post by admin »

Good suggestion. But in a valid while loop, there is no semicolon. So from another perspective, the existing code might be more confusing to some because it looks like a valid while loop with initialization section.
-Paul.

Post Reply

Who is online

Users browsing this forum: No registered users and 9 guests