Thread: logical operator OR not working?

1. logical operator OR not working?

hi, i'm trying to get a loop to end on either of two conditions.

Code:
```while ((numCorrect < theLength) || (wrongs < 9)) {

// do stuff

}```
both work fine on their own, it's just that when i put them together, the OR operator works like an AND operator; it doesn't stop the loop until BOTH conditions are true!! why is this happening?

2. Why don't you use && then? Say it:

"While the number correct is less than the length, and wrongs is less than nine, do stuff..."

Quzah.

3. With AND, both things must be true for the equation to stay true. The loop would stop if one term were false.

With OR, if one thing is true then the whole equation is true, so both sides must be false for the loop to stop.

4. good point... lol! I was thinking backwards, so i got them mixed up, coz i was thinking if either of them were false then stop... the "either" made me use OR instead of AND. thanks heaps guys.

5. It really does help to say it out loud. Just read it in words as you see it, and it's easy to figure that stuff out (most of the time).

Quzah.

Popular pages Recent additions