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
About Question enthuware.ocajp.i.v7.2.1366 :
Moderator: admin
-
- Posts: 20
- Joined: Tue Aug 27, 2013 3:16 am
- Contact:
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1366 :
Yes, while(k<7) is fine.
HTH,
Paul.
HTH,
Paul.
-
- Posts: 20
- Joined: Tue Aug 27, 2013 3:16 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1366 :
Thanks, Paul.
-
- Posts: 14
- Joined: Sun Dec 06, 2015 2:15 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1366 :
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.

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.

-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1366 :
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.
-Paul.
Who is online
Users browsing this forum: No registered users and 5 guests