Scripting reference · Nerdamer Language

if

Returns one of two values, depending on a condition.

Only the chosen branch is evaluated, so an error or assignment in the other one never happens.

The false branch is optional. Without it, a false condition gives no value, so use that form for a step that only sometimes runs, inside block.

Scripting

if(condition, whenTrue, whenFalse)

Write it in a script: nerdamer('if(1,5,6)'), or in the Playground.

Parameters

condition
Decides which branch runs.
whenTrue
The value when the condition is true.
whenFalse
Optional. The value when it is false.

Examples

The condition is true.

if(1,5,6)
// → 5
Open in Playground

The condition is false.

if(0,5,6)
// → 6
Open in Playground

x>0 can't be decided for an unknown x, so it counts as false.

if(x>0,1,2)
// → 2
Open in Playground

No false branch: the assignment is skipped.

block(x:1, if(0, x:2), x)
// → 1
Open in Playground

Good to know

  • A value is true when it isn't zero. An unknown symbol counts as true; a comparison that can't be decided, such as x>0 for an unknown x, counts as false.

Deprecated names

Deprecated.

IF still works, and gives the same result as if, but each call records an api.deprecatedFunction warning. Use if instead; the old name will be removed in a later major version.

← Back to Nerdamer Scripting