For(; ;)

Jan 5, 2013 at 5:37am
how to use for(; ;)
and how to stop it with break;
Jan 5, 2013 at 5:39am
1
2
for(;;)
  break;


Jan 5, 2013 at 5:40am
i want an Example
Jan 5, 2013 at 5:53am
The loop you described is really an endless loop. It has no condition with which it will terminate. This is usually done in video games, where the game runs a continuous loop until some condition breaks it and the game ends.

Is better to use this:

1
2
3
4
5
6
7
while(true)
{
//.... 

     if(Some_Condition)  //the user selects "quit" on the menu screen
       break;
}


Its better because its easier to read. But it accomplishes the same thing.
Jan 5, 2013 at 8:37am
while(true) is the same as for(;;). It's personal preference, although I tend to lead towards the while(true) as well.
Topic archived. No new replies allowed.