Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Conditional expressions

Conditional expressions are built from @if, @elseif, and @else. Conditions are evaluated from left to right until the first truthy branch succeeds.

@if 0: {
  zero
} @else: {
  nonzero
}
nonzero

Truthiness

All condition values are coerced to bool using the shipped 4.0 truthiness rules.

Data typeEvaluation
boolUnchanged.
string, list, map, range@true when non-empty; otherwise, @false.
float, int@true when nonzero. NaN is falsey.
nothingAlways @false.
tuple, selector, functionAlways @true.

Short-circuiting

Once a branch succeeds, later conditions are not evaluated and their bodies are not run.

@if @true: {
  pass
} @elseif [error: "should not run"]: {
  fail
}
pass