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,
ANDandORreturn one of their operands, not 1 or 0:5 AND 3is 3,0 OR 7is 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 = 0stores 1. Butn = NOT ystoresTRUEorFALSE, which printtrueandfalse. Test it withIF n THEN, notIF n = 1. - Order:
NOTcomes before the comparisons, which come beforeAND, which comes beforeOR. SoNOT a = bmeans(NOT a) = b: writea <> b. XORis not a logical or bitwise operator:5 XOR 3compiles, but the program does not start. Write~~for the bitwise exclusive or.- The words ignore case:
and,Orandnotwork.
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)) ' 3In the manual : Constants and operators