noob's question about the tutorial

This is a discussion on noob's question about the tutorial within the C++ Programming forums, part of the General Programming Boards category; why does this Code: #include <iostream> using namespace std; int main() { int x; x = -9; do {for ( ...

  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
    4,262
    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, 03: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, 03:36 AM
  4. another noob question;\
    By Pheonix in forum C++ Programming
    Replies: 11
    Last Post: 10-27-2003, 10:46 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21