Loop
Node Overview
Node name: Loop
Supported scenarios: Chatflow Agent (supported), Workflow Agent (supported)
Feature Description
The Loop node repeatedly executes the same logic according to a configured loop count or condition, and is commonly used for batch processing or repeated iterations. It provides powerful loop control capabilities, supporting both conditional loops and counted loops.
Node Display Content

1. Basic Information Display
- Icon: node-specific icon
- Name: node name
- Work modules inside the loop:
- The initial node inside the loop is Home
- Nodes can be added inside the loop (all except Start and End)
- Nodes inside the loop operate the same way as those outside
- The loop contains a special node (Exit Loop)
- Note: explanatory text added by the user
2. Action Buttons
- More button: click to display the context menu content
- Run button: click to enter the test run interface
Node Edit Panel

1. Loop Variable Configuration
- Purpose: used in evaluating the loop termination condition
- Variable management: multiple loop variables can be added
- Data production: each loop variable produces data during the loop
- Output variables: serve as output variables when the loop ends
2. Loop Termination Condition
- Condition configuration: multiple loop condition items are supported; the detailed logic is the same as the "condition items" of the IF/ELSE node
- Condition types: various condition checks are supported
- Logical relationship: AND/OR logical relationships are supported
3. Maximum Loop Count
- Range: minimum 1, maximum 100
- Safety control: prevents infinite loops
- Performance considerations: balance loop count against performance
4. Next Step Configuration
- Adding a next node is supported
Execution Logic
1. Loop Execution Flow
- Run the loop: start executing the loop logic
- Condition check: check whether the loop meets the termination condition or has reached the count limit
- Continue/stop: stop if the condition is met, continue otherwise
- Logging: each loop round records the loop's output conditions to the log
- Output results: when the loop ends, the final state of the loop variables serves as the output variables
2. Loop Control
- Condition control: control the loop based on condition checks
- Count control: control the loop based on the loop count
- Hybrid control: use both condition and count control simultaneously
Context Menu Actions
The context menu contains the following options:
- Change node: change the node type
- Copy: copy the node
- Duplicate: duplicate the node content
- Delete: delete the node
- Help link: jump to the help documentation
- Run node: test-run the current node
Test Run
- Support status: test run supported
- Change node: changing the node type is supported
- Copy features: copy, cut, and delete operations are supported
Use Cases
1. Batch Processing
- Data processing: process large amounts of data in batches
- File processing: process multiple files in batches
- API calls: call multiple APIs in batches
- Task execution: execute multiple tasks in batches
2. Iterative Computation
- Numerical computation: iteratively compute numerical results
- Algorithm implementation: implement iterative algorithms
- Optimization problems: solve optimization problems
- Convergence computation: compute convergent results
3. Status Checks
- Status monitoring: monitor system status
- Conditional waiting: wait for a specific condition to be met
- Polling checks: poll for status changes
- Timeout handling: handle timeout situations
4. Workflow Control
- Flow looping: control repeated flow execution
- Retry mechanisms: implement retry mechanisms
- Batch operations: perform batch operations
- Conditional execution: execute based on conditions
Loop Types
1. Conditional Loop
A loop based on condition checks:
WHILE condition is met:
execute loop body
update loop variables
check termination condition2. Counted Loop
A loop based on the loop count:
FOR i = 1 TO max count:
execute loop body
update loop variables
check termination condition3. Hybrid Loop
Using both condition and count:
FOR i = 1 TO max count:
IF condition is met:
execute loop body
update loop variables
check termination condition
ELSE:
exit earlyBest Practices
1. Loop Design
- Termination conditions: design clear termination conditions
- Loop variables: manage loop variables sensibly
- Performance considerations: consider the performance impact of the loop
- Error handling: add appropriate error handling
2. Condition Configuration
- Clear conditions: use clear condition logic
- Full coverage: make sure all cases are covered
- Performance optimization: optimize condition evaluation performance
- Maintainability: keep conditions easy to maintain
3. Variable Management
- Initialization: initialize loop variables correctly
- Update logic: design sensible variable update logic
- Type safety: make sure variable types are correct
- Scope: manage variable scope sensibly
4. Error Handling
- Exception catching: catch exceptions within the loop
- Error recovery: provide error recovery mechanisms
- Logging: record the loop execution process
- User messaging: provide friendly error messages
Configuration Steps
1. Basic Configuration
- Configure loop variables
- Set the loop termination condition
- Set the maximum loop count
2. Loop Body Configuration
- Add nodes inside the loop
- Configure the loop logic
- Set up variable updates
3. Condition Configuration
- Configure the termination condition
- Set up the condition logic
- Verify the condition correctness
4. Testing and Validation
- Test using the test run feature
- Check the loop execution results
- Verify the termination condition
FAQ
Q: How do I set the loop termination condition?
A: You can set multiple conditions with AND/OR logical relationships; the loop terminates when the condition is met.
Q: How do I determine the maximum loop count?
A: Set it based on business needs and performance considerations; the range is 1-100.
Q: How are loop variables managed?
A: Loop variables are updated during the loop and serve as output variables when the loop ends.
Q: How do I avoid infinite loops?
A: Set sensible termination conditions and a maximum loop count to ensure the loop can finish normally.
Q: How do I optimize loop performance?
A: Optimize the loop body logic, reduce unnecessary operations, and set a sensible loop count.
Considerations
- Termination conditions: make sure the loop has a clear termination condition
- Performance considerations: consider the impact of the loop on system performance
- Resource management: watch resource usage within the loop
- Error handling: add appropriate error handling mechanisms
- Logging: record the loop execution process to facilitate debugging