Pages: [1]   Go Down
Author Topic: is there "or" on arduino?  (Read 526 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 250
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Huntsville, Alabama, USA
Offline Offline
Sr. Member
****
Karma: 2
Posts: 327
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
if ((volume > MAX_VOL) || (time > MAX_TIME))
Code:
if ((value > 10) && (value < 100))  // value is 11 - 99

Regards,

-Mike

Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 240
Posts: 24449
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Read all about it:
http://arduino.cc/en/Reference/Boolean
Logged

"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.

0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 250
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thanks!!!
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 7
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: July 16, 2010, 09:31:49 pm by SuperLED » Logged

Huntsville, Alabama, USA
Offline Offline
Sr. Member
****
Karma: 2
Posts: 327
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Pages: [1]   Go Up
Jump to: