Examples
Practical Break node patterns for early exit, find-first, and error-on-detection scenarios.
Example 1: Find First Matching Pricing Rule
A pricing engine loops over rules in priority order. The first rule matching the order's attributes is applied and the loop exits. Without Break, all rules would be evaluated unnecessarily after a match is already found.
// Loop node
{
"node_type": "Loop",
"node_id": "EvaluatePricingRules",
"config": { "items": "pricingRules" }
}
// Inside loop body:
// → IfCondition: "$var.current_item.appliesToTier === $ctx.customer.tier"
// true:
// → SetVariable: matchedRule = $var.current_item
// → Break (no config)
// false:
// → (no connection, loop advances to next item)
// After loop done port:
// matchedRule contains the first applicable rule
// loop_completed_normally = false (if match was found before end)
// loop_completed_normally = true (if no rule matched — use default pricing)
Expected outcome: The loop stops at the first matching rule and the matched rule is captured. If no rule matches, the loop completes normally and the default pricing path handles the order.
Example 2: Stop CSV Import on Validation Error
A CSV import loop processes rows one by one. If a row fails validation, the Break node exits the loop and the error context is returned to the user.
// Loop: items = "csvRows"
// Body:
// → ValidateRowNode (HTTP call to validate service)
// → IfCondition: "$output.ValidateRowNode.valid === false"
// true:
// → SetVariable: importError = {
// rowIndex: $var.current_index,
// reason: $output.ValidateRowNode.error
// }
// → Break
// false:
// → ImportRowToDB → (no further body nodes)
// Done port IfCondition: "loop_completed_normally === true"
// true: → ReturnSuccessResponse
// false: → ReturnValidationErrorResponse (uses importError variable)
Expected outcome: Valid rows are imported. The first invalid row triggers Break and the entire import stops. The error response includes the row index and reason, letting the user correct the specific row before retrying.
Example 3: First Available Supplier Selection
Query multiple supplier APIs in preference order. Stop as soon as one returns available stock — avoid making redundant API calls to lower-priority suppliers.
// Loop: items = "suppliers" (ordered by preference)
// Body:
// → CallSupplierAPI (HTTP node, uses $var.current_item.apiUrl)
// → IfCondition: "$output.CallSupplierAPI.inStock === true"
// true:
// → SetVariable: selectedSupplier = $var.current_item
// → SetVariable: supplierPrice = $output.CallSupplierAPI.price
// → Break
// false:
// → (loop continues to next supplier)
// Done port:
// → PlaceOrderWithSupplier (uses selectedSupplier variable)
Expected outcome: The workflow queries suppliers one at a time in preference order. As soon as an available supplier is found, the remaining supplier APIs are not called, reducing latency and API costs.
Example 4: Security Check — Stop on First Violation
A security policy loop evaluates a list of access control rules. The first rule violation triggers an immediate break and access is denied without evaluating remaining rules.
// Loop: items = "accessControlRules"
// Body:
// → EvaluateRule (evaluates $var.current_item.expression against request context)
// → IfCondition: "$output.EvaluateRule.violated === true"
// true:
// → SetVariable: accessDeniedRule = $var.current_item.ruleName
// → Break
// false:
// → (continue checking remaining rules)
// Done port IfCondition: "loop_completed_normally === false"
// true (early break = violation found): → DenyAccessResponse
// false (all rules passed): → GrantAccessResponse
Expected outcome: Access is denied immediately when the first violated rule is detected, with the rule name logged for audit purposes. If all rules pass (loop completes normally), access is granted.