+ 1

If Statement

Why cant we use && in our if statement condition? Like if (var && var2 == 20) so we dont need to use more complex syntax.

2nd Jul 2019, 1:10 PM
KFPS
KFPS - avatar
1 ответ
0
Because the precedence of the logical operators are lower than the precedence of the comparison operators. I think that supporting var && var2 == 20 to be checked as var == 20 && var2 == 20 would cause even more problems. You can anyways define an additional function to support that logic. bool NewAnd(int x, int y, int z) {return x == z and y == z;} if (NewAnd(var, var2, 20))
2nd Jul 2019, 1:32 PM
Seb TheS
Seb TheS - avatar