I am having a problem with my program not reading the OR statements right.

do
{

blah blah blah

}while(y!=1||y!=2);

I have also used it as this format, ((y!=1)||(y!=2))

The program is marking it as true and keeping me stuck the loop even though y is == 1 or 2.

while(y!=1||y!=2);

Can you imagine any value of y for which at least one side of the OR isn't true?

The answer is no - if y=1, then the right hand side is true, so the whole OR statement is true. If y=2, then the left hand side is true, so the whole OR statement is true. If y= anything else, both sides are true so the whole OR statement is true.

You want it to keep going when: y does not equal one AND y does not equal two.

Edited 5 Years Ago by Moschops: n/a

while(y!=1||y!=2);

Can you imagine any value of y for which at least one side of the OR isn't true?

The answer is no - if y=1, then the right hand side is true, so the whole OR statement is true. If y=2, then the left hand side is true, so the whole OR statement is true. If y= anything else, both sides are true so the whole OR statement is true.

You want it to keep going when: y does not equal one AND y does not equal two.

Thank you so much. Can't believe I didn't notice that.

This question has already been answered. Start a new discussion instead.