AND, OR, NOT

Operator

Syntax

Combines conditions: AND is true when both sides are, OR when at least one is, and NOT reverses one. They are logical, not bitwise.

<a> AND <b>
<a> OR <b>
NOT <a>

Also written : AND, OR, NOT

Parts

<a>Any value or condition. 0, an empty string, FALSE and NULL count as false; anything else counts as true.
<b>Any value or condition. It is evaluated only when needed: skipped in a AND b when a is false, and in a OR b when a is true.

Good to know

  • On plain numbers, AND and OR return one of their operands, not 1 or 0: 5 AND 3 is 3, 0 OR 7 is 7. Classic BASICs compute bits here. For bits, use &&, || and !.
  • A whole comparison stored in a variable is 1 or 0: r = x > 0 AND y = 0 stores 1. But n = NOT y stores TRUE or FALSE, which print true and false. Test it with IF n THEN, not IF n = 1.
  • Order: NOT comes before the comparisons, which come before AND, which comes before OR. So NOT a = b means (NOT a) = b: write a <> b.
  • XOR is not a logical or bitwise operator: 5 XOR 3 compiles, but the program does not start. Write ~~ for the bitwise exclusive or.
  • The words ignore case: and, Or and not work.

Example

x = 5y = 0IF x > 0 AND y = 0 THEN Console("both")   ' bothIF x < 0 OR y = 0 THEN Console("one of them")   ' one of themIF NOT y THEN Console("y is zero")   ' y is zerov = 5 AND 3Console(Str(v))   ' 3
In the manual : Constants and operators