Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Short-circuit evaluation
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Precedence === Although {{code|AND}} takes [[operator precedence|precedence]] over {{code|OR}} in many languages, this is not a universal property of short-circuit evaluation. An example of the two operators taking the same precedence and being [[left-associative]] with each other is [[POSIX shell]]'s command-list syntax.<ref>{{cite web |title=Shell Command Language |url=https://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html |website=pubs.opengroup.org}}</ref>{{rp|at=Β§2.9.3}} The following simple left-to-right evaluator enforces a precedence of {{code|AND}} over {{code|OR}} by a {{code|continue}}: '''function''' short-circuit-eval (''operators'', ''values'') '''let''' ''result'' := True '''for each''' (''op'', ''val'') in (''operators'', ''values''): '''if''' ''op'' = "AND" && ''result'' = False '''continue''' '''else if''' ''op'' = "OR" && ''result'' = True '''return''' ''result'' '''else''' ''result'' := ''val'' '''return''' ''result''
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)