- Home /
Question by
hawken-2 · Jan 01, 2012 at 01:24 PM ·
loopwhilewhile-loop
or doesn't work in while loops?
Seems like asking for more than one statement to be true in a while loop causes it to loop endlessly.
while (bool1 == false)
works, if somewhere in the loop that boolean is made true. However:
while (bool1 == false || bool2 == false)
will just loop forever, even if either of the booleans are made true in the loop.
Anyone know of a way to check for more than one statement in a while conditional?
Comment
Answer by aldonaletto · Jan 01, 2012 at 02:10 PM
The second while will only stop when both variables are true. if you want to stop the loop when any of them is true, you should use && instead:
while (bool1==false && bool2==false)
In other words, this code will loop while bool1 and bool2 are both false.