Repeat
Applies a function to its own result, again and again.
Node id core/repeat
The Repeat node keeps a state: it starts from initial, and each call of
function gives the next state and whether to go on. It outputs the last
state. Use it for step-by-step processes where each step builds on the
previous one, such as a random walk or a growing pattern.
The function is a subgraph. To make one that fits,
drag a wire from Repeat's
function input onto empty canvas and choose
New function…, or right-click Repeat and choose New function….Inputs
| Name | Type | Default | Notes |
|---|---|---|---|
| initial | T | — | generic |
| function | Function(T, number, ...) -> (T, boolean) | — | generic |
| maxIterations | number | 100 | |
| arguments | A | — | multigenericindependent |
Outputs
| Name | Type | Notes |
|---|---|---|
| state | T | generic |
Behaviour
- The function has the type
Function(T, number, ...) -> (T, boolean): it gets the state and the iteration number (0 for the first call), and gives the new state andcontinue. See Functions. - Stopping. Repeat stops when the function gives
continue= false (the state from that call is kept), or aftermaxIterationscalls, whichever comes first.maxIterationsdefaults to 100. - No calls. With
maxIterations= 0, the output isinitial. - Extra arguments. Values connected to
arguments(a multi input) are passed to every call after the state and iteration, in slot order. Each slot may have its own type. - Each call is separate, with its own random numbers.
Errors
maxIterationsmust be a whole number from 0 to 10 000. The cap keeps a graph from looping (nearly) forever.functionmust be connected.- The function must take exactly as many extra parameters as there are
arguments, each of the right type, checked before any call. - If any call of the function fails, Repeat fails.