Skip to main content
These functions let an activity branch, repeat, and combine conditions. Comparisons and logical operators return a boolean1 (true) or 0 (false); see Operators and precedence.

If [if]

Evaluates comparison; returns true_statement if it is true, otherwise false_statement. Any expression can appear in any position, and if calls can be nested on either branch. comparison uses one of the comparison operators:
Use == (comparison) inside conditions, not = (assignment). See Operators and precedence.

Combining conditions

Combine comparisons with && (and), || (or), and ! (not). A good rule of thumb is to write the condition the way you would say it out loud.
Strict (>, <) and inclusive (>=, <=) comparisons differ exactly at the boundary value — choose deliberately. Nesting handles more than two outcomes — here, a different result for “more than 10 over,” “1–10 over,” and “not over”:

Choose [choose]

Returns the expression at position index (starting with 1) — a shorthand for a chain of if statements. index must be a whole number from 1 to N, an expression that evaluates to a whole number, or a Parameter out of range error is returned.

Loop [loop]

Repeats expression from from to to, building a table with one row per iteration. It increments by 1 (or by step, decrementing when to is below from), and ends when the index passes to. Two special variables are available inside the expression:
  • index — the current value of the loop counter. It starts at from and advances by step, so the default loop(1; n) runs 1, 2, … n while loop(1; 5; 2) runs 1, 3, 5.
  • last — the value from the previous iteration (0 on the first).
Any variable named index or last is ignored in favor of the loop’s own.

Building a series

Two loop patterns recur when projecting values over time. Compound growth — a value that grows at a fixed rate each period from a first-period base:
The index - 1 exponent holds the first period at base (^ 0 is 1), and ceil guards against a fractional periods. The result is one row per period. Running total — a cumulative sum across an existing table, with last as the accumulator:
Each row holds the total through that period, so the final row — item(result; length(result)) — is the all-up total. See item and length in Table functions.