Loop
Iterates over a list of Data objects, outputting one item at a time and aggregating results from loop inputs. Use it when you need to process each record separately in a workflow and then collect all results together.
How it Works
The Loop component receives a single input – a list of Data objects. It runs a short internal loop that takes the list one element at a time. During each pass it sends the current Data object out on the Item output. When all elements have been processed it sends a final signal on the Done output. No external services are called; all work happens inside the Nappai engine.
Inputs
- Data: The initial list of Data objects to iterate over.
Outputs
- Item: The current Data object in the loop. This output appears for every element in the list, one at a time.
- Done: A signal that the loop has finished. You can use this to trigger the next step after all items have been processed.
Usage Example
- Connect a component that produces a list of Data (e.g., a database query) to the Data input of Loop.
- Drag a component that processes a single Data object (e.g., a transform or API call) to the Item output.
- Optionally pipe the Done output to a component that aggregates the results or moves to the next workflow stage.
Important Notes
🔒 Handle sensitive data carefully 🟡
Data objects pass through memory during each loop iteration. If the data is sensitive, ensure it is encrypted or removed after use to prevent unintended exposure.
⚠️ No output for empty lists 🟡
If the input list of Data objects is empty, the Loop will not produce any output. Ensure the list contains at least one item or add a fallback path to handle the empty case.
📋 Input must be a Data list 🟢
The Loop expects a single input that is a list of Data objects. No additional configuration is needed.
💡 Collect results with an aggregator 🟢
If you need all results together, pipe the Loop output to an aggregator component. This collects each item into a single list or structure for later use.
💡 Limit list size for performance 🟢
Large lists increase memory usage and execution time. Split very long lists into smaller batches or use pagination when possible.
ℹ️ Sequential item output 🟢
During each iteration the component emits only the current Data object. Downstream steps will see one item at a time, not the entire list.
Tips and Best Practices
- Use an aggregator after the Loop if you need a single collection of processed items.
- Break large input lists into chunks to keep memory usage low.
- Add a conditional check before the Loop to handle empty lists gracefully.
- Encrypt or clear sensitive data after processing to maintain security.
Security Considerations
- Ensure any sensitive Data passed through the Loop is encrypted at rest and in transit.
- If the Loop is part of a workflow that outputs to external services, review those services’ security policies.
- Clear the loop’s internal memory after completion if handling confidential information.
- No Recursion: The Loop component does not allow recursion unless it is executed as part of a project flow. This is because the Loop processes data in memory and does not make external calls. If you need recursion, create a new flow that contains the Loop and the recursion.