Page 1 of 1

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

Posted: Tue Oct 18, 2016 9:35 am
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?

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

Posted: Tue Oct 18, 2016 9:21 pm
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.

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

Posted: Tue Oct 18, 2016 11:55 pm
by stevemann2705
oh yes. ok....

silly mistake.... :cry:

thanks!