Let's look at what you have right now:
1 2
|
if ( Number1[loop1] != 1 || 2 || 3 ){
}
|
With some parenthesis, this is essentially the same as
1 2
|
if ( (Number1[loop1] != 1) || (2) || (3) ){
}
|
Now, since anything non-zero evaluates to
true
, this is basically the same as
1 2
|
if ( (Number1[loop1] != 1) || true || true ){
}
|
This, of course, is always true.
Your last code is closer:
1 2
|
if ( loop1 != 1 || loop1 != 2 || loop1 != 3 ){
}
|
But remember that for a logical OR expression to be true, you only need one of the operands to be true, so this will also always evaluate to
true
.
(think: "I want a number that's either:
1) Not equal to 1, or
2) Not equal to 2, or
3) Not equal to 3."
Every number has that property!)
In short, to get what you want, use this:
1 2
|
if ( loop1 != 1 && loop1 != 2 && loop1 != 3 ){
}
|
(think: "I want a number that's
1) Not equal to 1,
and
2) Not equal to 2,
and
3) Not equal to 3."
Make more sense now?)
(Now, I'm not sure what
Number1 is or why it's not in your other two attempts, so I'll just leave it to you to figure out whether you need that or not.)
400!