OR operator in loops?

Jan 16, 2011 at 6:44pm
Whenever I seem to use || it just glitches up the program, and if either variable is true, it will keep looping.

As in

1
2
3
4
while(Bool1==false || Bool2==false)
{
Bool1=true;
}


Am I not supposed to be using an or for this?
Jan 16, 2011 at 6:46pm
I was meaning for it to be as if even one of the variables are true, and not false, it will break the loop.
Jan 16, 2011 at 6:53pm
If Bool2 is false it will loop forever, as you don't change Bool2 inside of the loop.
Jan 16, 2011 at 6:54pm
I thought && is supposed to make it where both need to be true? I'm confused.
Jan 16, 2011 at 7:03pm
Okay, somehow I got those mixed up, I guess I am trying to read things into English to much. :/
Jan 16, 2011 at 7:03pm
if you want it to loop when they are both false, and break when at least one is true

while ( Bool1 == false && Bool2 == false )

I think your confusion is coming from the fact that you're using a while loop and not an if statement, the condition in the brackets is what you want to be true in order to go into the loop, not when to break out of the loop

Last edited on Jan 16, 2011 at 7:04pm
Topic archived. No new replies allowed.