logical-or

Why is my c != 'o' || c != 'x' condition always true? [duplicate]

坚强是说给别人听的谎言 提交于 2019-11-26 02:15:41
This question already has an answer here: Why non-equality check of one variable against many values always returns true? 3 answers I have this loop statement, which I'll express using C-like syntax (C, C++, Java, JavaScript, PHP, etc. all use similar syntax): while (c != 'o' || c != 'x') { c = getANewValue(); } I want it to run until I get a 'o' or 'x' , but it never exits, even when c is 'o' or 'x' . Why not? I've also tried using if : if (c != 'o' || c != 'x') { // Show an error saying it must be either 'o' or 'x' } but that also always shows the error message, even when c is 'o' or 'x' .

Why is my c != 'o' || c != 'x' condition always true? [duplicate]

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-26 01:50:39
问题 This question already has answers here : Why non-equality check of one variable against many values always returns true? (3 answers) Closed last year . I have this loop statement, which I\'ll express using C-like syntax (C, C++, Java, JavaScript, PHP, etc. all use similar syntax): while (c != \'o\' || c != \'x\') { c = getANewValue(); } I want it to run until I get a \'o\' or \'x\' , but it never exits, even when c is \'o\' or \'x\' . Why not? I\'ve also tried using if : if (c != \'o\' || c !