OR Operator
See Also: AND operator, IAND operator, IOR operator, if command, if function, until, while
Purpose
To combine two variables into one expression that is true when either variable is true, and false only when both variables are false.
Syntax
( {var1} or {var2} )
where {var1} and {var2} may be either expressions, variables, or constants.
What It Does
When two variables are connected within an encompassing expression by or, the encompassing expression evaluates as true when either or both variables are true.
Example
move ((nWealth > 15000) or (nIncome > 5000)) to bRich
In this example, if either nWealth is greater than 15000 or nIncome is greater than 5000, the value of bRich will be true. Only if both expressions are false, meaning nWealth is less than 15000 and nIncome is less than 5000, will bRich evaluate to false.
Multiple or operators may be used to link more than two logical expressions into a single expression that evaluates true when any component expression is true, and false when all component expressions are false:
Example
move ((nWealth > 15000) or (nIncome > 5000) or (nInheritance > 250000)) to bRich
In this example, if either nWealth is greater than 15000, nIncome is greater than 5000, or nInheritance is greater than 250000, the value of bRich will be true. Only if all three expressions are false, meaning nWealth is less than 15000, nIncome is less than 5000, and nInheritance is less than 250000, will bRich evaluate to false.
Notes
-
There is no symbolic substitute for the word
or. -
When
andandorare intermingled in a single expression without grouping parentheses, evaluation proceeds from left to right with each operator connecting the next expression with the result of all previous (left-lying) ones.(true and false or true and false)would evaluate as false, while
(true or false and true or false)would evaluate as true.
-
When using variables other than Booleans (e.g., integers),
orexpressions do not necessarily return a value of 1. They return the first non-zero argument. Thus,(5 or 4)would evaluate as 5, while
(-2 or 3)would evaluate as -2.