Is this a valid if statement? [solved]

void setup() {
  // put your setup code here, to run once:
Serial.begin(57600);
}

void loop() {
  byte x = random(0, 255);

  Serial.println(x);
  if(x < 15 || x > 25 && x < 28 || x == 32 || x > 47 && x < 54){
    Serial.println("yep");
  }

  delay(200);
  
  // put your main code here, to run repeatedly:
}

I compiled it and it seems to work, but all i can do is eyeball/spot check it. Does this actually work.

What i want to do is only enter the if statement if x is less than 15, between 25 and 28, equal to 32, or between 47 and 54.

In my actual program, those numbers represent menu entries, and if those entries are selected, i want my arduino to do something spiffy.

Since this is a simple question, i have another question: Why does the arduino reset when i open the serial monitor? Sometimes need to do some debugging, but the bug isn’t present when the arduino first resets, so i either have to leave the serial monitor open, or try to reinact the series of steps that led to the bug… is there a way to prevent the serial monitor from resetting the arduino?

See http://en.cppreference.com/w/cpp/language/operator_precedence

&& is higher than ||

If I were you I would use parentheses to make sure that it is evaluated how you want it to be.

is there a way to prevent the serial monitor from resetting the arduino?

Yes, try Google. I think you put a capacitor between /RESET and GND to stop it resetting. There's also a link on some of the boards you can cut if you want a more permanent solution.

Thank you for your quick response. Sorry it was an addon question.

If i added parenthesis, would it be something like this?

if((x < 15) ||( x > 25 && x < 28) ||( x == 32) ||( x > 47 && x < 54)){
    Serial.println("yep");
  }

??

Yes, that looks better.

 x > 25 && x < 28

That could be:

 (x == 26) || (x == 27)