-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 Muhammad
  • 527
  • 9
  • 18
FalsePride
  • 47
  • 1
  • 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 Muhammad
  • 527
  • 9
  • 18
0

You want to use AND, which is &&

user3094755
  • 1,319
  • 12
  • 17