Scripting reference · Nerdamer Language

while

Repeats an expression while a condition is true.

The condition is checked before each pass. while returns the value of the last pass.

Scripting

while(condition, body)

Write it in a script: nerdamer('block(x:0,while(3-x,x:x+1),x)'), or in the Playground.

Parameters

condition
Checked before each pass; the loop stops when it is false.
body
The expression to repeat. Use block for several steps.

Examples

Count up until 3-x is zero.

block(x:0,while(3-x,x:x+1),x)
// → 3
Open in Playground

The same loop with a comparison.

block(x:0, while(x<3, x:x+1), x)
// → 3
Open in Playground

Good to know

  • break() leaves the loop and continue() skips to the next pass.
  • If the body never runs, while has no value, and using it as one is an error.
  • A loop stops with an error after MAX_LOOP_ITERATIONS passes (1,000,000 by default); see Settings.

← Back to Nerdamer Scripting