Sep 22, 2011 at 6:48am UTC
Hi, I am a really beginner, I need help with this loop, I know it is an infinite loop but what else is wrong with it?
int x=0;
while (x)
{
++x;
cout<<x<< endl;
)
Sep 22, 2011 at 6:53am UTC
The last parenthesis should be } instead of ).
Sep 22, 2011 at 6:56am UTC
oops! I am sorry, I typed it wrong. Do you see any other problem? Something obvious?
When I tried to run the code in express, it doesn't run, it says to press any key to continue. So it means that is not an infinite loop...I don't know..
Last edited on Sep 22, 2011 at 7:04am UTC
Sep 22, 2011 at 6:58am UTC
Well, x == 0 at the start so...
Sep 22, 2011 at 7:10am UTC
x=0, not x==0; it is not the same...I don't understand, so the first problem with this loop is that it doesn't cout ( is that the right expression?)
Thank you so much!
Sep 22, 2011 at 7:48am UTC
while (x)
is the same as
while (x != false )
x is 0 in the start so it never executes the loop code
Sep 22, 2011 at 7:30pm UTC
Great! Thank you very much!!