another quick newb C question

alyarb

Platinum Member
Jan 25, 2009
2,425
0
76
Is it possible to say

if var1=x and var2=y {then do this;}

such that two conditions must be met for a function to be performed? thanks
 

Cogman

Lifer
Sep 19, 2000
10,286
145
106
if ((var1 == x) and (var2 == y)) {
do stuff;
}

That should work. The short hand is

if ((var1 == x) && (var2 == y)){
do stuff;
}
 

Crusty

Lifer
Sep 30, 2001
12,684
2
81
You don't need the inner sets of () in your case, he just put them there for readability. Boolean operators have an order of precedence, && before ||. So if you have a complex if statement you'll need to use ( ) to control the order of operations of the boolean statement.

Foe example.

(x == a || (x == b && y == a)) is the same as (x == a || x == b && y == a).

However, those are both different from ((x == a || x == b) && y == a)