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?
About Question enthuware.ocajp.i.v8.2.1233 :
Moderator: admin
-
- Posts: 2
- Joined: Tue Oct 18, 2016 9:31 am
- Contact:
-
- Site Admin
- Posts: 10066
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1233 :
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.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 2
- Joined: Tue Oct 18, 2016 9:31 am
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1233 :
oh yes. ok....
silly mistake....
thanks!
silly mistake....
thanks!
Who is online
Users browsing this forum: No registered users and 214 guests