Pololu Robotics & Electronics
Menu
My account Comments or questions? About Pololu Contact Ordering information Distributors

Nesting if with AND OR


#1

I am working on an application where multiple sensor values need to be evaluated. Normally I would use:

if ( (acx < 100) && (acy > 100) ) { do things; }
Now I need to do things when acx value is either below 50 or above 150, can I nest this the following way?

if ( ((acx < 50)||(acx > 150)) && (acy > 100) ) { do other things; }
Or are there better ways to do this?


#2

Hello.

Yes, you can nest your conditions like that in a single IF statement.

- Amanda


#3

Thank you, this cleaned up my IF, AND and OR statements, it works