-3

I need to know how to look for two values in if statement. I know about a method where the code will be executed when at least one value matches the specified number like in here:

if (x == 0 || y == 0) {
  // code to be called
}

But the code above will be executed even if one value matches 0 and the other not. What's the way to check if both x and y are equal to 0?

I couldn't find the answer anywhere...

Islam Hassan
  • 673
  • 1
  • 10
  • 21
FalsePride
  • 53
  • 3
  • 12

2 Answers2

2

Use the AND operator instead of the OR operator, that is

if (x == 0 && y == 0) {
// code to be called
}
Islam Hassan
  • 673
  • 1
  • 10
  • 21
0

You want to use AND, which is &&

user3094755
  • 1,561
  • 16
  • 20