Skip to the content.

if / else

let x = 5

if (x > 10) do
    term.log("big")
else if (x > 0) do
    term.log("small positive")
else do
    term.log("zero or negative")

Single-statement form

If the body is a single statement, do can be omitted:

let factorial(x) = do
    let n = x - 1
    if (n) return x*factorial(n)
    return 1

(from factorial.ar)

Truthiness

Any value can be used as a condition. 0, null, false, and empty strings/collections are falsy; everything else is truthy. In the factorial.ar example above, if (n) is shorthand for “if n is not zero”.

Ternary expression

For simple conditional expressions (not statements), see the ternary operator described in Operators:

let sign = a < b ? -1 : a > b ? 1 : 0

Next