code bypasses my if statement for some reason? what am i doing wrong?

I know I must have messed something up but I can’t figure it out. the boolean I made called “add” is initialized to LOW. Then when the card is scanned it changes to HIGH so that it doesn’t move the servo after adding a card until it is scanned a second time. but on line 185, I wrote && (add == LOW) meaning it should only pass if add is equal to low. for some reason, add I equal to high and it still passes, I even put Serial.println(add) in the if statement to make sure and sure enough despite passing it was high.

as you can probably tell I’m new and still learning but if someone can tell me what I did wrong that would be great. Thanks!

heres the specific part but the full codes attatched:

else if ((content.substring(1) == card2) || (content.substring(1) == card3) || (content.substring(1) == card4) || (content.substring(1) == card5) && (mastercard == LOW) && (add == LOW))
{
Serial.println(“Authorized access”);
Serial.println();
unlock.write(165);
delay(3000);
unlock.write(10);
}

rfid_open.ino (5.34 KB)

Because of the operator precedence (&& is higher than ||, and left to right)The && conditions are being combined with the card5 in the last of four conditions OR'd together.

Add some parenthesis to clarify your intentions. Possibly

else if (((content.substring(1) == card2) || (content.substring(1) == card3) || (content.substring(1) == card4) || (content.substring(1) == card5)) && (mastercard == LOW) && (add == LOW))

cattledog:
Because of the operator precedence (&& is higher than ||, and left to right)The && conditions are being combined with the card5 in the last of four conditions OR’d together.

Add some parenthesis to clarify your intentions. Possibly

else if (((content.substring(1) == card2) || (content.substring(1) == card3) || (content.substring(1) == card4) || (content.substring(1) == card5)) && (mastercard == LOW) && (add == LOW))

cattledog:
Because of the operator precedence (&& is higher than ||, and left to right)The && conditions are being combined with the card5 in the last of four conditions OR’d together.

Add some parenthesis to clarify your intentions. Possibly

else if (((content.substring(1) == card2) || (content.substring(1) == card3) || (content.substring(1) == card4) || (content.substring(1) == card5)) && (mastercard == LOW) && (add == LOW))

thank you