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
Ternary conditional operator
(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!
==Conditional assignment== Originally from ALGOL 60 the conditional assignment of ALGOL is: ''variable'' := '''if''' ''condition'' '''then''' ''expression_1'' '''else''' ''expression_2''; {{code|?:}} is used as follows: ''condition'' ? ''value_if_true'' : ''value_if_false'' The ''condition'' is evaluated ''true'' or ''false'' as a [[Boolean expression]]. On the basis of the evaluation of the Boolean condition, the entire expression returns ''value_if_true'' if ''condition'' is true, but ''value_if_false'' otherwise. Usually the two sub-expressions ''value_if_true'' and ''value_if_false'' must have the same type, which determines the type of the whole expression. The importance of this type-checking lies in the operator's most common useβin [[Conditional (programming)|conditional]] [[Assignment (computer science)|assignment]] statements. In this usage it appears as an [[Expression (programming)|expression]] on the right side of an assignment [[Statement (programming)|statement]], as follows: ''variable'' = ''condition'' ? ''value_if_true'' : ''value_if_false''; The ?: operator is similar to the way conditional expressions ('''if-then-else''' constructs) work in [[functional programming]] languages, like [[Scheme (programming language)|Scheme]], [[ML (programming language)|ML]], [[Haskell]], and [[XQuery]], since if-then-else forms an expression instead of a statement in those languages.
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)