用户工具

站点工具


en:reference:language:boolean
no way to compare when less than two revisions

差别

这里会显示出您选择的修订版和当前版本之间的差别。


前一修订版
en:reference:language:boolean [2023/06/07 04:23] (当前版本) – 外部编辑 127.0.0.1
行 1: 行 1:
 +====== Boolean Operators ======
 +
 +
 +These can be used inside the condition of an if statement.
 +===== && (logical and) =====
 +
 +True only if both operands are true, e.g.
 +<code>
 +if (digitalRead(2) == HIGH  && digitalRead(3) == HIGH) { // read two switches 
 +  // ...
 +
 +</code>
 +is true only if both inputs are high.
 +===== || (logical or) =====
 +
 +True if either operand is true, e.g.
 +<code>
 +if (x > 0 || y > 0) {
 +  // ...
 +
 +</code>
 +is true if either x or y is greater than 0.
 +===== ! (not) =====
 +
 +True if the operand is false, e.g.
 +<code>
 +if (!x) { 
 +  // ...
 +
 +</code>
 +is true if x is false (i.e. if x equals 0).
 +===== Warning =====
 +
 +Make sure you don't mistake the boolean AND operator, && (double ampersand) for the bitwise AND operator & (single ampersand). They are entirely different beasts.
 +
 +
 +Similarly, do not confuse the boolean || (double pipe) operator with the bitwise OR operator | (single pipe).
 +
 +
 +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.
 +===== Examples =====
 +<code>
 +if (a >= 10 && a <= 20){}   // true if a is between 10 and 20
 +</code>
 +
  
en/reference/language/boolean.txt · 最后更改: 2023/06/07 04:23 由 127.0.0.1