About Question enthuware.ocajp.i.v8.2.1233 :

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

Moderator: admin

Post Reply
stevemann2705
Posts: 2
Joined: Tue Oct 18, 2016 9:31 am
Contact:

About Question enthuware.ocajp.i.v8.2.1233 :

Post by stevemann2705 »

Explaination says: "In the first iteration of for loop, the while loop keeps running till c becomes 6. Now, for all next for loop iteration, the while loop never runs as the flag is false. So final value of c is 6."

I think while loop keeps running till c becomes 5 instead of 6 because the while loop is:
while(flag){
c++;
if(i>c || c>5) flag = false;
}


and not
while(flag){
c++;
if(i>c || c>=5) flag = false;
}



Am I missing something?

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

Re: About Question enthuware.ocajp.i.v8.2.1233 :

Post by admin »

No, the explanation is correct. When c is equal to 5, flag will not become false because the condition is c>5 i.e. only if c is greater than 5. Therefore, when c=5, flag remains true and the loop will execute another iteration and c will be incremented to 6. Now, c is greater than 5 and so flag will be set to false. This will cause the while loop to not pursue the next iteration.

HTH,
Paul.

stevemann2705
Posts: 2
Joined: Tue Oct 18, 2016 9:31 am
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1233 :

Post by stevemann2705 »

oh yes. ok....

silly mistake.... :cry:

thanks!

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 5 guests