Syntax:
result& = exprA {or | ||} exprB
Description:
Expression exprA
and expression exprB
are each interpreted as 32-bit integer quantities. The or
operator performs a "bitwise comparison" of each bit in exprA
with the bit in the corresponding position in exprB
. The result is another 32-bit quantity; each bit in the result is determined as follows:
Bit Value in expr | Bit Value in expr | Bit Value in expr |
0 | 0 | 0 |
1 | 0 | 1 |
0 | 1 | 1 |
1 | 1 | 1 |
The or
operator can also be used to join two "condition clauses" for use in statements like if
, while
and until
. For example:
if n > 17 or myName$ = "Smith" then beep
This statement produces a beep if either n > 17
is true, or myName$="Smith"
is true, or both.
Even when it's used to join condition clauses, the or
operator still does a "bitwise comparison." This happens because FutureBasic actually assigns a numeric value to every condition clause, depending on whether the clause is true or false. for example, the clause n>17
is evaluated as -1 if it's true, or as 0 if it's false. Conversely, any numeric expression is judged as "true" if it's non-zero, or as "false" if it's zero.
Example:
In the following example, expressions are evaluated as true or false before a decision is made for branching. The logical expression state$="IL"
is true, and therefore evaluated as -1. The expression state$="CA"
is false, and is therefore evaluated as 0. Then the bitwise comparison (-1)or(0)
is performed, resulting in -1. Finally, the long if
statement interprets this -1 result as meaning "true," and therefore executes the first print
statement.
state$ = "IL"
long if state$ = "IL" or state$ = "CA"
print "Okay"
xelse
print "Invalid state"
end if
The example below shows how bits are manipulated with or
:
defstr long
print bin$(923)
print bin$(123)
print "--------------------------------"
print bin$(923 or 123)
program output:
00000000000000000000001110011011
00000000000000000000000001111011
--------------------------------
00000000000000000000001111111011
See Also:
not; and; xor; Appendix D - Numeric Expressions