# Thread: Evaluating multiple expressions in an If statement.

1. ## Evaluating multiple expressions in an If statement.

Hi there,

My first post on this forum so please be gentle...

how do i evaluate a variable to see if it is equal to more than one value in an IF statement.

For example if i want to do something based on if variable is equal to 5

Code:
```if (variable == 5){
//do something
}
else...```
but how do i write it if i want to do it based on if variable is either equal to 5 or 10?

many thanks.

2. Then you use "or" (also written "||").

3. if (x == y || x == z)
Basically. Same for and.
if (x == y && x == z)

4. Just to clarify a bit:
Code:
`if (x == y && x == z)`
is the same as:
Code:
`if (x == y && y == z)`
since x == y & x == z is only true if y == z (because x can only have one value, and if it's equal to y, then y and z must be equal for x == z to be true).

--
Mats

5. Ah yes, but I was demonstrating a common pitfall, such as:
if (x == y || z)
Which in real life would be read as if x is equal to y or z, but in programming it would be read by the compiler as
if x equals y OR true (false)
If z is anything else but 0, it will always be true and thus will not do what you expect.
It is thus important to explicitly specify the variable to compare to. Unless you were comparing something as a boolean expression, of course, but many makes this mistake.
The very same thing applies to and, as well.