If statements multiple operations

Hey everyone! I am making a sensor-based guide system and it seems like my program over lapse each other or the operations in my if/else statement are not doing what I want it to do.

I wonder if I can use AND “&&” with OR “||” like:

distance1>5 && (distance2<=5 || distance3<=5).

Does the operation inside the “()” acts like one operation or it is just the same as:
distance1>5 && distance2<=5 || distance3<=5 ?

I wanted it to work with my first statement, but it seems like I’m not able to do so.
I need help.

this is my code:

if (distance5<570 && distance5>420){
Serial.println(“UP STAIR”);
}
else if(distance5>570 && distance5<710){
Serial.println(“DOWN STAIR”);
}
else if(distance5<420 || distance5>710){
Serial.println(“TURN RIGHT”);

else if(distance1>500 && ( distance2<=500|| distance3<=500 || distance4<=500 )){
Serial.println(“TURN RIGHT”);

}
else if(distance1<=500){
Serial.println(“TURN LEFT”);

}
else if((distance1 <=500 && distance2<=500)&&(distance3<=500 || distance4<=500)){
Serial.println(“ROTATE”);

}
else{
Serial.println("")
}

Hi, Welcome to the forum.

Please read the first post in any forum entitled how to use this forum. http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code. It will be formatted in a scrolling window that makes it easier to read.

Thanks.. Tom.. :)

Does the operation inside the "()" acts like one operation

The tests in brackets will be evaluated first and, as you suggest, the result will be used with other tests not in the brackets, or in other brackets.

You don't strictly need to use the brackets if the tests are done in the right order (which I can never remember) so using brackets is a good idea.

&& is evaluated first.

a && b || c   is   (a && b) || c