1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Best way to break out of loop

Discussion in 'C++' started by Ducky, Sep 4, 2010.

  1. Ducky

    Ducky New Member

    Joined:
    Sep 4, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    What would be the best way to break out of a loop in a timely manner, after a few secs for example. ( I dont need exactitude.)
    I know about the GetTickCount() method but i think it would be least CPU intensive to just increment and check against an integer.

    Is there a better way?

    Code:
    size_t i=0;
    
    while (1)
    {
                i++;
                // Do something again and again...
    
                // ... and now break out.
                if (i > 99)
                {
                    return;
                }
     }
     

Share This Page