ANDALSO: 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
No edit summary |
No edit summary |
||
Line 24: | Line 24: | ||
File:Osx.png|'''yes''' | File:Osx.png|'''yes''' | ||
</gallery> | </gallery> | ||
<!-- Additional availability notes go below | <!-- Additional availability notes go below here --> | ||
Line 36: | Line 36: | ||
{{Cl|NEXT}} index | {{Cl|NEXT}} index | ||
{{Text|<nowiki>' value of index is now | {{Text|<nowiki>' value of index is now > 10</nowiki>|#919191}} | ||
{{Cl|PRINT}} {{Text|<nowiki>"Trying _ANDALSO"</nowiki>|#FFB100}} | {{Cl|PRINT}} {{Text|<nowiki>"Trying _ANDALSO"</nowiki>|#FFB100}} | ||
{{Text|<nowiki>' _ANDALSO performs short-circuiting logical conjunction and hence the GetArrayValue check is completely bypassed</nowiki>|#919191}} | {{Text|<nowiki>' _ANDALSO performs short-circuiting logical conjunction and hence the GetArrayValue check is completely bypassed</nowiki>|#919191}} | ||
{{Cl|IF}} index | {{Cl|IF}} index >= {{Text|1|#F580B1}} {{Cl|_ANDALSO}} index <= {{Text|10|#F580B1}} {{Cl|_ANDALSO}} {{Text|GetArrayValue|#55FF55}}(values(), index, v) {{Cl|THEN}} | ||
{{Cl|PRINT}} {{Text|<nowiki>"_ANDALSO: Value ="</nowiki>|#FFB100}}; v | {{Cl|PRINT}} {{Text|<nowiki>"_ANDALSO: Value ="</nowiki>|#FFB100}}; v | ||
{{Cl|ELSE}} | {{Cl|ELSE}} | ||
Line 51: | Line 51: | ||
{{Text|<nowiki>' AND does not performs short-circuiting logical conjunction and hence QB64-PE will throw a runtime error: Subscript out of range</nowiki>|#919191}} | {{Text|<nowiki>' AND does not performs short-circuiting logical conjunction and hence QB64-PE will throw a runtime error: Subscript out of range</nowiki>|#919191}} | ||
{{Cl|IF}} index | {{Cl|IF}} index >= {{Text|1|#F580B1}} {{Cl|AND (boolean)|AND}} index <= {{Text|10|#F580B1}} {{Cl|AND (boolean)|AND}} {{Text|GetArrayValue|#55FF55}}(values(), index, v) {{Cl|THEN}} | ||
{{Cl|PRINT}} {{Text|<nowiki>"AND: Value ="</nowiki>|#FFB100}}; v | {{Cl|PRINT}} {{Text|<nowiki>"AND: Value ="</nowiki>|#FFB100}}; v | ||
{{Cl|ELSE}} | {{Cl|ELSE}} |
Revision as of 12:09, 8 December 2024
_ANDALSO is a boolean logical operator that performs short-circuiting logical conjunction on two expressions.
Syntax
- result = firstvalue _ANDALSO 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 both expressions evaluate to true, result is true.
Availability
Examples
Example: AND versus _ANDALSO
DIM AS LONG index, values(1 TO 10), v FOR index = 1 TO 10 values(index) = RND * 255 NEXT index ' value of index is now > 10 PRINT "Trying _ANDALSO" ' _ANDALSO performs short-circuiting logical conjunction and hence the GetArrayValue check is completely bypassed IF index >= 1 _ANDALSO index <= 10 _ANDALSO GetArrayValue(values(), index, v) THEN PRINT "_ANDALSO: Value ="; v ELSE PRINT "_ANDALSO: Outside range." END IF PRINT PRINT "Trying AND" ' AND does not performs short-circuiting logical conjunction and hence QB64-PE will throw a runtime error: Subscript out of range IF index >= 1 AND index <= 10 AND GetArrayValue(values(), index, v) THEN PRINT "AND: Value ="; v ELSE PRINT "AND: Outside range." END IF END FUNCTION GetArrayValue%% (arr() AS LONG, idx AS LONG, value AS LONG) value = arr(idx) GetArrayValue = -1 ' return true END FUNCTION |
See also
- Featured in our "Keyword of the Day" series
- _BIT, &B, _BYTE
- AND, XOR, OR
- AND (boolean), XOR (boolean), OR (boolean)
- _ORELSE, _NEGATE
- Binary, Boolean
- Mathematical Operations