Thread: noob's question about the tutorial

  1. #1
    Registered User
    Join Date
    May 2012
    Posts
    3

    noob's question about the tutorial

    why does this
    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();
    }
    print out a "count 0" line??!?

  2. #2
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    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

  3. #3
    Registered User
    Join Date
    May 2012
    Posts
    3
    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!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. noob question
    By mouse666666 in forum C Programming
    Replies: 0
    Last Post: 01-12-2011, 04:58 AM
  2. noob question
    By dhuan in forum C++ Programming
    Replies: 1
    Last Post: 11-02-2010, 05:00 AM
  3. Noob Question
    By bumfluff in forum C++ Programming
    Replies: 4
    Last Post: 11-06-2005, 04:36 AM
  4. another noob question;\
    By Pheonix in forum C++ Programming
    Replies: 11
    Last Post: 10-27-2003, 11:46 AM