Think about what
if ((state != 10) || (state != 15) || (state != 19) || (state != 22) || (state != 33) || (state != 39) || (state != 47) || (state != 48) || (state != 49) || (state != 51))
means. ||
means "or." The negation of this is (by DeMorgan's Laws):
state == 10 && state == 15 && state == 19...
In other words, the only way that this could be false if if a state
equals 10, 15, and 19 (and the rest of the numbers in your or statement) at the same time, which is impossible.
Thus, this statement will always be true. State 15 will never equal state 10, for example, so it's always true that state
will either not equal 10 or not equal 15.
Change ||
to &&
.
Also, in most languages, the following:
if (x) {
return true;
}
else {
return false;
}
is not necessary. In this case, the method returns true
exactly when x
is true and false
exactly when x
is false
. You can just do:
return x;