Or
Operator
For Boolean expressions, returns “true” if one or more expressions are true. For integer expressions, does a bitwise OR operation.
Syntax
expression_1 Or expression_2
Parts
expression_1
- A Boolean or integer expression.
expression_2
- A Boolean or integer expression.
Instructions
For Boolean expressions, the result is false only if expression_1
is false and expression_2
is false at the same time.
The table that follows shows how to find this result.
If expression_1 is |
And expression_2 is |
Then the result is |
---|---|---|
True | True | True |
True | False | True |
False | True | True |
False | False | False |
Note:
The operator Or
always evaluates the two expressions.
This includes procedure calls, which can have side effects.
A different operator, Or Else
, does not evaluate the second expression if the first is false.
For bitwise operations, the operator Or
compares each bit at the same position in the two numeric expressions.
The table that follows shows how to calculate the bit in the result.
If the bit in expression_1 is |
And the bit in expression_2 is |
Then the bit in the result is |
---|---|---|
1 | 1 | 1 |
1 | 0 | 1 |
0 | 1 | 1 |
0 | 0 | 0 |
Note: The logical and bitwise operators have lower precedence than the arithmetic and relational operators. Thus, we recommend that you put parentheses around bitwise operations to make sure they give correct results.
Examples
Var a = 240, b = 15, c = 16
Var a_or_b = a Or b
Var a_or_c = a Or c
Var b_or_c = b Or c
a |
240 (11110000) |
---|---|
b |
15 (00001111) |
c |
16 (00010000) |
a_or_b |
255 (11111111) |
a_or_c |
240 (11110000) |
b_or_c |
31 (00011111) |