
Overview
The Loop Controller Block is a powerful tool that allows you to create loops in your flow. It’s the only block in Odella that can contain cycles of blocks, including itself. This block maintains the state of the loop and controls the flow of values through it.Key Features
- Maintains loop state
- Controls value flow through the loop
- Dynamic number of input-default pairs
- Dynamic number of output ports
- Conditional loop continuation
Inputs
If truthy, the loop continues executing. If falsy, the loop stops. Coerced to boolean. Optional, defaults to true if not provided or if the value is “Not Ran”.
The value that changes in each iteration of the loop. The number of inputs is dynamic based on connections. Each input has a corresponding default input.
The initial value for the corresponding Input X. Required for each Input X. If any default input is control-flow-excluded, all outputs will be control-flow-excluded.
Outputs
If the
Continue input is falsy, this output runs with an array of all input values. Does not run if Continue is truthy, instead outputting a control-flow-excluded value.The current iteration number, starting at 1 for the first iteration.
The value of the corresponding input or default input. On the first iteration, it’s the value from the default input. On subsequent iterations, it’s the value from the input on the previous iteration. The number of outputs matches the number of inputs.
Editor Settings
The maximum number of iterations the loop can run.
What should happen when max iterations is reached:
error: Throw an error (default)break: Break the loop as if Continue was false
Example: AI Chatting To Itself
This example demonstrates a loop that continues indefinitely:- Add a Loop Controller block to your flow.
- Connect a Chat block to the Loop Controller’s input.
- Combine the existing message history with the AI’s response.
- Feed the combined history back into the Loop Controller.
This loop will never break on its own. It will fail after 100 iterations by default unless “At Max Iterations” is set to “break”.
Example: Iterating Over an Array
This example shows how to iterate over an array and append ” Mapped” to each element:- Use a Pop Block to remove the first value from the array.
- Append ” Mapped” to the popped value.
- Push the new value into an output array using an Array Block.
- Use a Compare Block to check if the input array is empty and break the loop.
- Connect an Output block to the
Breakoutput of the Loop Controller.
Error Handling
The Loop Controller Block will error if:- The loop exceeds the maximum number of iterations and “At Max Iterations” is set to “error”
- Any required default inputs are not connected
FAQ
Why do I need to connect something to the Break output port?
Why do I need to connect something to the Break output port?
The flow needs to traverse from the output blocks to the input block due to processing requirements. The “Break” output port provides a convenient connection point, even if the loop never breaks.
Why does my loop run forever?
Why does my loop run forever?
If the “Continue” input port is not connected, it defaults to
true, causing the loop to never break. Also, if a “Not Ran” output (e.g., from an If Block) is connected to the input port, it will always be true.What happens if I don't connect the default input port?
What happens if I don't connect the default input port?
If any default inputs are control-flow-excluded, all outputs will be control-flow-excluded. Always connect all default inputs.
How can I remember the ports better?
How can I remember the ports better?
Input ports come in pairs (Input X and Input X Default). The block will automatically name outputs based on connected input block names.
Why does the loop controller have a maximum number of iterations?
Why does the loop controller have a maximum number of iterations?
This prevents accidental infinite loops. You can choose whether to error or break when the maximum is reached using the “At Max Iterations” setting.


