Foreach List◀ (Inspire)
Close the loop and return the accumulated result
- flow_control
- remained_list
- intermediate_output
- result
The other half of the loop. Where ▶Foreach List starts an iteration and hands you the current item, this node closes it: you feed it whatever you produced this pass, and it either loops back for the next item or, when the list is exhausted, spits out the final accumulated result. Think of it as the "next" that also doubles as the "done."
You never use this one alone - it's meaningless without a ▶Foreach List upstream. Together they turn ComfyUI's flat per-item list execution into a proper loop that can build something up across items: a running composite, a progressively edited image, a value tallied over a list. That accumulate-across-iterations behaviour is the whole reason the pair exists, and it's why this end node's job is to carry your work back to the beginning until there's nothing left to process.
How it works
Each iteration, the begin node gives you an item and the running intermediate_output. You transform them, then pass the new value into this node's intermediate_output input. This node checks the remained_list: if items are left, it loops control back to the begin node for the next one; if the list is empty, it stops and emits the accumulated value on result.
The inputs and outputs that matter
- flow_control (
FOREACH_LIST_CONTROL) - comes straight from the begin node'sflow_controloutput; the loop's control signal. - remained_list (
ITEM_LIST) - also straight from the begin node; how the loop knows what's left. - intermediate_output - your result for this iteration, the thing that gets carried forward.
Output: result - the final accumulated value once every item has been processed.
Installing it
ComfyUI Manager: search "Inspire Pack", install, restart. Or manually:
cd ComfyUI/custom_nodes
git clone https://github.com/ltdrdata/ComfyUI-Inspire-Pack
Then restart. Ships in Dr.Lt.Data's Inspire Pack.
Where people get tripped up
Wiring is where loops die. The README is blunt about it: connect the begin node's flow_control and remained_list outputs directly into this node's matching inputs - don't route them through anything in between, and don't cross them. The only input you actually feed with your own work is intermediate_output; the other two are pure loop plumbing. Get those backwards or run them through a reroute and the loop either won't iterate or won't terminate. And remember the value you keep is whatever you pass to intermediate_output each pass - if you forget to fold the current item into it, the loop runs but result comes out as just the initial value, untouched. One neat trick from the pack: if you pass an emptied list (via Drop List) into the loop, it terminates immediately, which is a clean way to bail out early.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| flow_control | FOREACH_LIST_CONTROL | Directly connect the output of ForeachListBegin, the starting node of the iteration. | |
| remained_list | ITEM_LIST | Directly connect the output of ForeachListBegin, the starting node of the iteration. | |
| intermediate_output | * | Connect the intermediate outputs processed within the iteration here. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| result | * | This is the final output value. |