I have seen: Canonical, language-agnostic question for if(var != "x" || var != "y" ...)
That question solicits a canonical for a similar but slightly different problem, but mentions the same problem in the question. An answer reads:
I'm planning to write one as soon as I find time though, so that we could close them all.
But the answer was written a decade ago and mentioned only JS. A good language-agnostic canonical exists for the similar if (x != a || x != b ...)
problem in the linked question: Why does non-equality check of one variable against many values always return true?
Several canonical questions exist for the if (x == a || b || c ...)
problem but only for specific languages:
- Python: Why does "a == x or y or z" always evaluate to True? How can I compare "a" to all of those?
- Java: How to format multiple 'or' conditions in an if statement
- C++: Most efficient way to compare a variable to multiple values?
I am considering creating a single cross-language canonical for this common beginner error to serve as a dupe target for miscellaneous questions to which no language-specific canonical exists. A good if (x != a || x != b ...)
canonical was created a decade ago as a response to the old question. I am wondering if creating a language-agnostic canonical to the similar but different if (x == a || b || c ...)
problem would bring still benefit to the community now in 2024. I have seen this and this but one says 'Go for it' and other says 'Don't even bother.'