Arduino> Structure> Boolean Operators>
!
[Boolean Operators]
Description
Logical NOT results in a
true
if the operand is false
and vice versa.Example Code
This operator can be used inside the condition of an if statement.
if (!x) { // if x is not true
// statements
}
It can be used to invert the boolean value.
x = !y; // the inverted value of y is stored in x
Notes and Warnings
The bitwise not ~ (tilde) looks much different than the boolean not ! (exclamation point or "bang" as the programmers say) but you still have to be sure which one you want where.
-------------------------------------------------------------------&&
[Boolean Operators]
Description
Logical AND results in
true
only if both operands are true
.Example Code
This operator can be used inside the condition of an if statement.
if (digitalRead(2) == HIGH && digitalRead(3) == HIGH) { // if BOTH the switches read HIGH
// statements
}
Notes and Warnings
Make sure you don’t mistake the boolean AND operator, && (double ampersand) for the bitwise AND operator & (single ampersand). They are entirely different beasts.
-------------------------------------------------------------------||
[Boolean Operators]
Description
Logical OR results in a
true
if either of the two operands is true
.Example Code
This operator can be used inside the condition of an if statement.
if (x > 0 || y > 0) { // if either x or y is greater than zero
// statements
}
Notes and Warnings
Do not confuse the boolean || (double pipe) operator with the bitwise OR operator | (single pipe).
-------------------------------------------------------------------
Post a Comment
Hi Users, if you have any queries then please let me know.