Page 1 of 1
About Question enthuware.ocajp.i.v7.2.1366 :
Posted: Mon Nov 25, 2013 12:45 pm
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
Re: About Question enthuware.ocajp.i.v7.2.1366 :
Posted: Mon Nov 25, 2013 1:43 pm
by admin
Yes, while(k<7) is fine.
HTH,
Paul.
Re: About Question enthuware.ocajp.i.v7.2.1366 :
Posted: Tue Nov 26, 2013 4:56 am
by Zoryanat
Thanks, Paul.
Re: About Question enthuware.ocajp.i.v7.2.1366 :
Posted: Sun Dec 06, 2015 2:18 pm
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.

Re: About Question enthuware.ocajp.i.v7.2.1366 :
Posted: Sun Dec 06, 2015 8:45 pm
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.