Jan 15, 2014 at 2:03am Jan 15, 2014 at 2:03am UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14
bool running = true ;
int x = 1;
while (running)
{
std::cout << "This is message " << x << "." << std::endl;
std::cout << "Press enter to continue..." << std::endl;
std::cin.ignore();
if (x >= 10)
running = false ;
else
x++;
}
while(true){} is essentially an infinite loop that allows you to explicitly break out under multiple circumstances you define.
Last edited on Jan 15, 2014 at 2:06am Jan 15, 2014 at 2:06am UTC
Jan 15, 2014 at 8:12am Jan 15, 2014 at 8:12am UTC
In the most games there is a central while() loop which goes on all the time until the user cancelles.
So, the while condition has always to be true. Different developers use different expressions; there are
1 2 3 4 5
while (1)
while (true )
while (1==1)
for (;;)
for (;true ;)
Last edited on Jan 16, 2014 at 9:09am Jan 16, 2014 at 9:09am UTC
Jan 15, 2014 at 9:17am Jan 15, 2014 at 9:17am UTC
while (0) is equivalent to while (false) which would make the loop pointless.
Jan 16, 2014 at 8:39am Jan 16, 2014 at 8:39am UTC
Oh, thank you. Are there any other techniques to cancel out the bool other than what Vemc showed in his post?
Last edited on Jan 16, 2014 at 8:39am Jan 16, 2014 at 8:39am UTC