why does thisprint out a "count 0" line??!?Code:#include <iostream> using namespace std; int main() { int x; x = -9; do {for ( ;x < 10; x++ ) cout<<"Count: "<<x<< " Hello, world!\n"; } while ( x != 0 ); cin.get(); }
why does thisprint out a "count 0" line??!?Code:#include <iostream> using namespace std; int main() { int x; x = -9; do {for ( ;x < 10; x++ ) cout<<"Count: "<<x<< " Hello, world!\n"; } while ( x != 0 ); cin.get(); }
The same reason it runs "forever".
The `for' loop runs to completion every time the outer `do' loop iterates.
In other words, `x' never has the value zero in the outer `do' loop.
Soma
Ah! I see, it IS running forever... It seemed to have stopped at the 19th line and I assumed that it was done. I saw the count 0 line and improperly closed the window w/ the upper right "x" button. If I had bothered to hit hit enter I would have seen it was still running and given the code some more thought!! thank you!