ORELSE: Difference between revisions
Jump to navigation
Jump to search
Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link
(Initial version.) |
No edit summary |
||
(One intermediate revision by one other user not shown) | |||
Line 1: | Line 1: | ||
{{DISPLAYTITLE:_ORELSE}} | |||
[[_ORELSE]] is a [[Boolean|boolean]] logical operator that performs short-circuiting inclusive logical disjunction on two expressions. | [[_ORELSE]] is a [[Boolean|boolean]] logical operator that performs short-circuiting inclusive logical disjunction on two expressions. | ||
Line 77: | Line 78: | ||
{{PageSeeAlso}} | {{PageSeeAlso}} | ||
* [https://qb64phoenix.com/forum/showthread.php?tid=2661 Featured in our "Keyword of the Day" series] | |||
* [[_BIT]], [[&B]], [[_BYTE]] | * [[_BIT]], [[&B]], [[_BYTE]] | ||
* [[AND]], [[XOR]], [[OR]], [[_ANDALSO]], [[_NEGATE]] | * [[AND]], [[XOR]], [[OR]] | ||
* [[AND (boolean)]], [[XOR (boolean)]], [[OR (boolean)]] | |||
* [[_ANDALSO]], [[_NEGATE]] | |||
* [[Binary]], [[Boolean]] | * [[Binary]], [[Boolean]] | ||
* [[Mathematical Operations]] | * [[Mathematical Operations]] |
Latest revision as of 22:37, 25 May 2024
_ORELSE is a boolean logical operator that performs short-circuiting inclusive logical disjunction on two expressions.
Syntax
- result = firstvalue _ORELSE secondvalue
Description
- A logical operation is said to be short-circuiting if the compiled code can bypass the evaluation of one expression depending on the result of another expression.
- If the result of the first expression evaluated determines the final result of the operation, there is no need to evaluate the second expression, because it cannot change the final result.
- Short-circuiting can improve performance if the bypassed expression is complex, or if it involves procedure calls.
- If either or both expressions evaluate to true, result is true.
Availability
Examples
Example: OR versus _ORELSE
PRINT "Trying _ORELSE" ' _ORELSE performs short-circuiting logical conjunction and hence for "strawberry", only isFruit() is called IF isFruit("strawberry") _ORELSE isRed("strawberry") _ORELSE isSeasonal("strawberry") THEN PRINT "Probably a strawberry." ELSE PRINT "Certainly not a strawberry." END IF PRINT PRINT "Trying OR" ' OR does not performs short-circuiting logical conjunction and hence all is***() functions are called IF isFruit("strawberry") OR isRed("strawberry") OR isSeasonal("strawberry") THEN PRINT "Probably a strawberry." ELSE PRINT "Certainly not a strawberry." END IF END FUNCTION isFruit%% (fruit AS STRING) PRINT "isFruit() called!" isFruit = (fruit = "strawberry") END FUNCTION FUNCTION isRed%% (fruit AS STRING) PRINT "isRed() called!" isRed = (fruit = "strawberry") END FUNCTION FUNCTION isSeasonal%% (fruit AS STRING) PRINT "isSeasonal() called!" isSeasonal = (fruit = "strawberry") END FUNCTION |
Trying _ORELSE isFruit() called! Probably a strawberry. Trying OR isFruit() called! isRed() called! isSeasonal() called! Probably a strawberry. |
See also
- Featured in our "Keyword of the Day" series
- _BIT, &B, _BYTE
- AND, XOR, OR
- AND (boolean), XOR (boolean), OR (boolean)
- _ANDALSO, _NEGATE
- Binary, Boolean
- Mathematical Operations