Arduino-boolean-operators
提供:Dev Guides
Arduino-ブール演算子
変数Aが10を保持し、変数Bが20を保持すると仮定します-
Operator name | Operator simple | Description | Example |
---|---|---|---|
and | && | Called Logical AND operator. If both the operands are non-zero then then condition becomes true. | (A && B) is true |
or | |||
Called Logical OR Operator. If any of the two operands is non-zero then then condition becomes true. | (A | B) is true | |
not | ! | Called Logical NOT Operator. Use to reverses the logical state of its operand. If a condition is true then Logical NOT operator will make false. | !(A && B) is false |
例
void loop () {
int a = 9,b = 4
bool c = false;
if((a > b)&& (b < a))
c = true;
else
c = false;
if((a == b)|| (b < a))
c = true;
else
c = false;
if( !(a == b)&& (b < a))
c = true;
else
c = false;
}
結果
c = true
c = true
c = true