x


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?

more ▼

asked Jan 01 '12 at 01:24 PM

hawken gravatar image

hawken
91 19 24 25

(comments are locked)
10|3000 characters needed characters left

1 answer: sort newest

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.

more ▼

answered Jan 01 '12 at 02:10 PM

aldonaletto gravatar image

aldonaletto
41.5k 16 42 197

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x295
x60
x17

asked: Jan 01 '12 at 01:24 PM

Seen: 428 times

Last Updated: Jan 01 '12 at 02:13 PM