# How to make several conditions for an if statement?

I want to say something like

if(x == 1) and (y == 2)

how would I say that?

If you want to say “and”:

``````if(x == z && y == z){
//Do something
}
``````

If you want to say “or”:

``````if(x == z || y == 0){
//Do something
}
``````

A decent article on Microsofts site

Mod Edit: Took a stab at re-sourcing the link. Searched ms173145 and got Operators

I know that this wasn’t the exact question but let’s get a bit fancy - if you want to test your variables against multiple condition values say to see if x is 1,2 or 3 and y is 4,5 or 6 then you can do this just to give a bit of knowledge on how to use Generics and Linq which are fantastic

``````var x = 1;
var y = 4;

if ((new List<int>() {1,2,3}).Count(i => x == i) > 0 &&
(new List<int>() {4,5,6}).Count(i => y == i) > 0)
{
/* do something */
}
``````

You can use the following but I wanted to give an example of lambda expressions

if ((new List() {1,2,3}).Contains(x) &&
(new List() {4,5,6}).Contains(y))
{
/* do something */
}

One thing I’m confused about is when you can or can’t use && because I get errors sometimes when trying to use && with player input.