Examples
Real-world Loop node configurations for invoice processing, email dispatch, and early-exit patterns.
Example 1: Process Invoice Line Items
Iterate over the line items extracted from an invoice document. For each item, validate the product code and accumulate the total amount. After all items are processed, the done port triggers the approval step.
{
"node_type": "Loop",
"node_id": "ProcessLineItems",
"config": {
"items": "invoice.lineItems"
},
"connections": {
"body": ["ValidateProductCode"],
"done": ["SubmitForApproval"]
}
}
// ValidateProductCode node uses:
// $var.current_item.sku → product code for lookup
// $var.current_item.qty → quantity
// $var.current_item.price → unit price
// $var.current_index → item position for error reporting
Expected outcome: For a 5-line invoice, the ValidateProductCode node fires 5 times, each time receiving the corresponding line item. After all 5 pass validation, the SubmitForApproval node fires once with the fully validated invoice context.
Example 2: Bulk Email Dispatch
Loop over a list of marketing campaign recipients and send a personalised email to each. Track the number of successfully sent emails in an accumulator variable.
{
"node_type": "Loop",
"node_id": "SendCampaignEmails",
"config": {
"items": "campaignRecipients"
},
"connections": {
"body": ["PersonaliseEmailContent"],
"done": ["SendCampaignSummaryReport"]
}
}
// Before the loop, a Set Variable node initialises:
// sentCount = 0
// PersonaliseEmailContent uses:
// $var.current_item.email
// $var.current_item.firstName
// After sending, a Set Variable node increments:
// sentCount = $var.sentCount + 1
Expected outcome: Each recipient receives a personalised email. After the loop, sentCount holds the total dispatched count. SendCampaignSummaryReport uses this value to notify the campaign manager of delivery totals.
Example 3: Cart Validation with Early Break
Validate stock availability for each cart item. Exit the loop immediately if any item is out of stock and route to a stock-alert page instead of proceeding to checkout.
{
"node_type": "Loop",
"node_id": "ValidateCartStock",
"config": {
"items": "cart.items"
},
"connections": {
"body": ["CheckStockAvailability"],
"done": ["ProceedToPayment"]
}
}
// CheckStockAvailability → IfCondition (inStock check)
// true: → (no further body nodes, loop advances to next item)
// false: → SetVariable (outOfStockSku = $var.current_item.sku)
// → Break node (exits loop early)
// Loop "done" port fires after Break:
// loop_completed_normally = false
// outOfStockSku = "SKU-442"
// ProceedToPayment node checks loop_completed_normally:
// if false → redirect to stock alert page
Expected outcome: If all items are in stock, the loop completes normally and the customer proceeds to payment. If any item is out of stock, the Break exits the loop early, outOfStockSku is populated, and the done port routes to a stock-unavailable message.
Example 4: Payroll Processing with Skipping
Process payroll for each employee in the batch. Skip employees who are on unpaid leave (their pay is zero), using a Continue node to advance to the next employee without running the full payroll calculation.
{
"node_type": "Loop",
"node_id": "ProcessPayrollBatch",
"config": {
"items": "employees"
},
"connections": {
"body": ["CheckLeaveStatus"],
"done": ["SubmitBankTransferBatch"]
}
}
// CheckLeaveStatus → IfCondition
// condition: "$var.current_item.onUnpaidLeave === true"
// true: → Continue node (skip payroll calc for this employee)
// false: → CalculateGrossPay → CalculateDeductions
// → GeneratePayslip
// After the loop completes:
// SubmitBankTransferBatch receives all calculated pay records
Expected outcome: Employees on unpaid leave are skipped without error. All other employees receive full payroll calculations. The batch submission node receives the accumulated payslip data for all processed employees.
Example 5: Iterating a Simple String Array
Loop over a list of email addresses (simple string array) to send password reset links. Demonstrates that the Loop node works equally well with arrays of primitives, not just arrays of objects.
{
"node_type": "Loop",
"node_id": "SendPasswordResets",
"config": {
"items": "adminEmailList"
},
"connections": {
"body": ["SendResetEmail"],
"done": ["LogResetCompletion"]
}
}
// adminEmailList = ["alice@acme.com", "bob@acme.com", "carol@acme.com"]
// For each iteration, current_item is the email string directly:
// SendResetEmail uses: $var.current_item as the recipient address
// current_index used for logging: "Sent reset 1 of 3", "2 of 3", etc.
Expected outcome: Three password reset emails are dispatched, one per address in the array. The LogResetCompletion node fires once after all three are sent, recording the event with loop_total_items = 3 and loop_completed_normally = true.