Docs docs docs.

This commit is contained in:
Bob Nystrom
2014-04-11 10:45:20 -07:00
parent 634e4396cb
commit cd75e17f0d
9 changed files with 189 additions and 78 deletions
+8 -1
View File
@@ -58,4 +58,11 @@ An `||` ("logical or") expression is reversed. If the left-hand argument is trut
IO.print(false || 1) // 1
IO.print(1 || 2) // 1
**TODO: Conditional operator.**
## The conditional operator `?:`
Also known as the "ternary" operator since it takes three arguments, Wren has the little "if statement in the form of an expression" you know and love from C and its bretheren.
:::dart
IO.print(1 != 2 ? "math is sane" : "math is not sane!")
It takes a condition expression, followed by `?`, followed by a then expression, a `:`, then an else expression. Just like `if`, it evaluates the condition. If true, it evaluates (and returns) the then expression. Otherwise it does the else expression.