
Module 5 Lesson 4: Loop Mechanisms
Round and round. Compare the different ways to iterate in n8n, from automated node-level loops to advanced manual loops for pagination.
Module 5 Lesson 4: Loop Mechanisms
Understanding how n8n moves data through nodes is the hardest part for beginners. There are three types of "Loops" happening at different levels.
1. Automatic "Execution Per Item"
If Node A outputs 5 items... ...Node B will run 5 times automatically.
- This is n8n's "Secret Sauce." You don't have to write
for each item. n8n handles the repetition for you.
2. Manual Looping (The "Circle")
If you are dealing with Pagination (e.g., "The API only gives me 100 results, but I need all 500").
- Get Page 1.
- Action.
- Check: "Is there a 'next_page' URL?" (IF Node).
- Yes: Connect back to Step 1, using the new URL.
- No: Finish.
3. The "Item Lists" Node
Sometimes you want to Stop the automatic looping.
- Scenario: You have 100 items, and you want to put them all into ONE single email.
- The Fix: Use the "Item Lists" node with "Summarize" or "Join" to turn the 100 items into 1 single item containing an array.
4. Why Automatic Loops can be "Dangerous"
If Node A has 100 items... ...and Node B is "Send Slack Message"... ...you will send 100 Slack Messages in 1 second!
- Rule: If you want one summary message, you MUST use an Aggregate or Item Lists node before the Slack node.
Exercise: The Loop Hunt
- Create a Code node that outputs 3 items:
[{json:{id:1}}, {json:{id:2}}, {json:{id:3}}]. - Connect a Set node after it. Set
processed = true. - Run it. Does the Execution Log show 3 separate node runs?
- Add an Aggregate node after the Set node.
- Now how many times does the node after the Aggregate run? (Hint: See Module 4, Lesson 3).
- Research: What is "Max Iterations" in a loop to prevent an INFINITE cycle that crashes your server?
Summary
Looping in n8n is "Magic" until you need to control it. By understanding the difference between automatic per-item execution and manual pagination loops, you can build workflows that are both powerful and predictable.
Next Lesson: Reusable logic: Global Workflows and the 'Execute Workflow' node.