Loop
The Loop block is a container block in Sim that allows you to create iterative workflows by executing a group of blocks repeatedly. Loops enable iterative processing in your workflows.
The Loop block supports four types of iteration:
Loop blocks are container nodes that can hold other blocks inside them. The blocks inside a loop will execute multiple times based on your configuration.
Overview
The Loop block enables you to:
Iterate over collections: Process arrays or objects one item at a time
Repeat operations: Execute blocks a fixed number of times
Loop on conditions: Continue executing while or until a condition is met
Aggregate results: Collect outputs from all loop iterations
How It Works
The Loop block executes contained blocks through sequential iteration:
- Initialize Loop - Set up iteration parameters (count or collection)
- Execute Iteration - Run contained blocks for current iteration
- Collect Results - Store output from each iteration
- Continue or Complete - Move to next iteration or finish loop
Configuration Options
Loop Type
Choose between four types of loops:
For Loop (Iterations) - A numeric loop that executes a fixed number of times:

Use this when you need to repeat an operation a specific number of times.
Example: Run 5 times
- Iteration 1
- Iteration 2
- Iteration 3
- Iteration 4
- Iteration 5ForEach Loop (Collection) - A collection-based loop that iterates over each item in an array or object:

Use this when you need to process a collection of items.
Example: Process ["apple", "banana", "orange"]
- Iteration 1: Process "apple"
- Iteration 2: Process "banana"
- Iteration 3: Process "orange"While Loop (Condition-based) - Continues executing while a condition evaluates to true:

Use this when you need to loop until a specific condition is met. The condition is checked before each iteration.
Example: While <variable.i> < 10
- Check condition → Execute if true
- Inside loop: Increment <variable.i>
- Inside loop: Variables assigns i = <variable.i> + 1
- Check condition → Execute if true
- Check condition → Exit if falseDo-While Loop (Condition-based) - Executes at least once, then continues while a condition is true:

Use this when you need to execute at least once, then loop until a condition is met. The condition is checked after each iteration.
Example: Do-while <variable.i> < 10
- Execute blocks
- Inside loop: Increment <variable.i>
- Inside loop: Variables assigns i = <variable.i> + 1
- Check condition → Continue if true
- Check condition → Exit if falseHow to Use Loops
Creating a Loop
- Drag a Loop block from the toolbar onto your canvas
- Configure the loop type and parameters
- Drag other blocks inside the loop container
- Connect the blocks as needed
Accessing Results
After a loop completes, you can access aggregated results:
- <loop.results>: Array of results from all loop iterations
Example Use Cases
Processing API Results
Scenario: Process multiple customer records
- API block fetches customer list
- ForEach loop iterates over each customer
- Inside loop: Agent analyzes customer data
- Inside loop: Function stores analysis results
Iterative Content Generation
Scenario: Generate multiple variations
- Set For loop to 5 iterations
- Inside loop: Agent generates content variation
- Inside loop: Evaluator scores the content
- After loop: Function selects best variation
Counter with While Loop
Scenario: Process items with counter-based loop
- Initialize workflow variable: i = 0
- While loop with condition: <variable.i>< 10
- Inside loop: Agent processes item at index <variable.i>
- Inside loop: Variables increments i = <variable.i> + 1
- Loop continues while i is less than 10
Advanced Features
Limitations
Container blocks (Loops and Parallels) cannot be nested inside each other. This means:
- You cannot place a Loop block inside another Loop block
- You cannot place a Parallel block inside a Loop block
- You cannot place any container block inside another container block
If you need multi-dimensional iteration, consider restructuring your workflow to use sequential loops or process data in stages.
Loops execute sequentially, not in parallel. If you need concurrent execution, use the Parallel block instead.
Inputs and Outputs
- Loop Type: Choose between 'for', 'forEach', 'while', or 'doWhile' 
- Iterations: Number of times to execute (for loops) 
- Collection: Array or object to iterate over (forEach loops) 
- Condition: Boolean expression to evaluate (while/do-while loops) 
- loop.currentItem: Current item being processed 
- loop.index: Current iteration number (0-based) 
- loop.items: Full collection (forEach loops) 
- loop.results: Array of all iteration results 
- Structure: Results maintain iteration order 
- Access: Available in blocks after the loop 
Best Practices
- Set reasonable limits: Keep iteration counts reasonable to avoid long execution times
- Use ForEach for collections: When processing arrays or objects, use ForEach instead of For loops
- Handle errors gracefully: Consider adding error handling inside loops for robust workflows
