Or
From Xojo Documentation
Used to perform a logical Or comparison between two Boolean expressions or a bitwise Or comparison between two integers.
Usage
result = expression1 Or expression2
Part | Type | Description |
---|---|---|
result | Boolean or Integer | A Boolean value if expression1 and expression2 are boolean and an integer if expression1 and expression2 are integers. |
expression1 | Boolean or Integer | Any valid Boolean or integer expression. Expression1 and expression2 must be of the same data type. |
expression2 | Boolean or Integer | Any valid Boolean or integer expression. Expression1 and expression2 must be of the same data type. |
Notes
The Or operator is overloaded. If it is passed two booleans, it performs a logical Or and returns a boolean. If it is passed two integers, it performs a bitwise Or operation on the integers and returns an integer. In this case, it is equivalent to calling the BitOr method of the Bitwise class.
In the first instance, if either boolean expression evaluates to True, then result is True. If both expressions evaluate to False then result is False. The truth table for logical operators is shown below.
Expression1 | Expression2 | Or | And | Xor |
---|---|---|---|---|
True | True | True | True | False |
True | False | True | False | True |
False | True | True | False | True |
False | False | False | False | False |
If you pass two integers, Or returns an integer that is the result of comparing each bit of the two integers passed and assigning 1 to the bit position in the integer returned if either of the bits in the same position in the integers passed are 1. Otherwise, 0 is assigned to the bit position.
The following table shows the results for bitwise operators:
Integer1 | Integer2 | Or | And | Xor |
---|---|---|---|---|
0 | 0 | 0 | 0 | 0 |
0 | 1 | 1 | 0 | 1 |
1 | 0 | 1 | 0 | 1 |
1 | 1 | 1 | 1 | 0 |
Sample Code
This example uses the Or operator to perform logical comparisons
Var b As Boolean
Var c As Boolean
Var d As Boolean
a = True
b = False
d = a Or b // d = True
d = b Or c // d = False
Using Or with Integer values:
See Also
And, Not, Xor operators; Bitwise class; Operator_Or function; Operator precedence