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!
===Dart=== The [[Dart (programming language)|Dart]] programming language's syntax belongs to the [[C (programming language)|C]] family, primarily inspired by languages like Java, C# and JavaScript, which means it has inherited the traditional {{code|?:}} syntax for its conditional expression. Example: <syntaxhighlight lang="Dart"> return x.isEven ? x ~/ 2 : x * 3 + 1; </syntaxhighlight> Like other conditions in Dart, the expression before the {{code|?}} must evaluate to a [[Boolean]] value. The Dart syntax uses both {{code|?}} and {{code|:}} in various other ways, which causes ambiguities in the language grammar. An expression like: <syntaxhighlight lang="Dart"> { x as T ? [1] : [2] } </syntaxhighlight> could be parsed as either a "set literal" containing one of two lists ''or'' as a "map literal" <code>{((x as T?)[1]) : [2]}</code>. The language always chooses the conditional expression in such situations. Dart also has a second ternary operator, the {{code|1=[]=}} operator commonly used for setting values in lists or maps, which makes the term "the ternary operator" ambiguous in a Dart context.
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)