Go Down

Topic: is there "or" on arduino? (Read 696 times) previous topic - next topic

acmiilangr

I was searching on google and i couldnt find anywhere the "or" syntax.
i need it for example like this.
if (    ) or (   ) {

}

i know i can check it 2 times but i want the correct syntax

Mike Murdock

acmiilangr,

I think you want the logical OR operator.  The operator is: ||

Similarly, the logical AND operator is: &&

The logical NOT operator is: !

Do not get these mixed up with the bit operators: | & ^
Code: [Select]
if ((volume > MAX_VOL) || (time > MAX_TIME))
Code: [Select]
if ((value > 10) && (value < 100))  // value is 11 - 99

Regards,

-Mike


AWOL

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.


SuperLED

#4
Jul 17, 2010, 04:29 am Last Edit: Jul 17, 2010, 04:31 am by SuperLED Reason: 1
if ( x > y || x > z) { var++; }

I don't think you need that extra "( )", as mentioned earlier, but it is a good habit and makes the code cleaner.

Mike Murdock

Quote
if ( x > y || x > z) { var++; }

I don't think you need that extra "( )", as mentioned earlier, but it is a good habit and makes the code cleaner.
Absolutely right.  Just as you don't need the '{' and '}' in the example you gave.

Regards,

-Mike

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy