This is related to the issue asked about in this other question.
For the sake of this question, let's assume that we have a variable v that can have any value from the set of values
"a", "b", "c", ..., "z"
In this case then the programmers wants to have specific code executed when the value of v
is not "x"
, "y"
, or "z"
.
So the following IF statement is constructed:
if (v != "x" || v != "y" || v != "z") {//do something}
Above statement would always return true, due to that the 3 conditions using negation are checked independently of each other.
Consequently, at any given time, any single one of the 3 conditions can evaluate to TRUE, leading to the entire IF statement evaluating to TRUE.
Anyway so the question I wanted to ask is, does this behavior or situation have a formal name, and if so, what is it?
if
statement you give is true, sincev
can't be simultaneously equal to three different things so it's guaranteed that at least two of the conditions are true. And Boolean OR by definition evaluates to true if at least one of its arguments is true. So I'm not sure what behaviour you're talking about. $\endgroup$"x"
,"y"
or"z"
" would be written!(v=="x" || v=="y" || v=="z")
$\endgroup$