OR

From Microduino Wiki
Revision as of 08:45, 10 August 2016 by Fengfeng (talk) (Created page with "*'''Boolean operators''' These operators can be used in if conditional statement. *'''&&(Logical and)''' Only both the two operands are true is it be true. For example...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
  • Boolean operators

These operators can be used in if conditional statement.

  • &&(Logical and)

Only both the two operands are true is it be true. For example:


if (digitalRead(2) == HIGH  && digitalRead(3) == HIGH) { // read the levels of the two switch 
// ...
}

When both input levels are high levels, it is true.

  • ||(Logical or)

If only one operand is true, it is true. For example:


if (x > 0 || y > 0) {
  // ...
}

If x or y is larger than 0, it is true

  • !(Logical negation)

If operand is false, it is true For example


if (!x) { 
  // ...
}

If x is false, it is true(namely, x is equal to 0).

  • For example

if (a >= 10 && a <= 20){}   // if the value of a is between 10 and 20, it is true
  • Note

You mustn't take the bitwise operator “and” whose sign is &(single) as same to boolean operator“and” whose sign is &&(double), which are completely different operators.

In the same way, don’t mix boolean operator || and bitwise operator “or”| up .

Bitwise operator 〜(tilde)looks like very different from boolean operator not!(just as the programmer say :“bang”). But you still should to confirm which operator you want.


[Return to Arduino Syntax Manual]