For Each Close
The accumulator for your iterate-over-anything loop
- flow
- value
- value
Every For Each loop from ComfyUI-ForLoops ends at one of these. For Each Close is the terminator for the loop that iterates over up to 50 connected values instead of an integer range - and like its plain-For sibling, it's the half that actually does the work. The Open node just feeds you the current item; this node decides when the loop is over and carries your result across the finish line.
If you've read the For Close article, this one will feel familiar, because the two share the exact same engine. The differences are the flow type and what you're iterating over.
How it works
For Each Close reads the flow object from its matching Open node - that object carries the current index and the item count. If it's the last item, it returns the accumulated value and the loop ends. Otherwise it gathers every node downstream of the Open node (your whole loop body, Save Image and Preview included), clones them, advances to the next item, and runs the copy through ComfyUI's graph-expansion engine - same official GraphBuilder mechanism the plain For loop uses. One Queue Prompt, N iterations, no scripting.
The flow wire is typed JK_FOREACH_FLOW, which is the guardrail: plug a For Each Open into a plain For Close and it won't connect. It's an intentional error, not a limitation.
Inputs and outputs that matter
flow(required) - from For Each Open → flow. Must be a For Each flow; the type system enforces it.value(optional) - connect the end of your loop body here. This is where per-item results accumulate: each iteration's output becomes the next iteration'sinitial_valueon the Open node, and when the last item is done, the final accumulated result comes out of this node'svalueoutput.value(output) - the finished accumulator. Feed this to whatever comes after the loop.
That value connection also forces ordering, which matters more here than it looks: it guarantees the whole body finishes for the current item before the loop advances. If you're saving images per item, that's the difference between tidy outputs and a race.
Installing it
Same shared install as the whole pack - one command, then restart:
cd ComfyUI/custom_nodes
git clone https://github.com/jeankassio/ComfyUI-ForLoops
Or ComfyUI Manager → search "ComfyUI-ForLoops" → install. No dependencies, no models, nothing else. This is one of the lighter installs in the custom-node world: a single Python file plus a little JS for the dynamic sockets.
A quick example
The pack's ForEach_example.json workflow does the classic accumulation demo: three strings into For Each Open, each one concatenated onto the previous result through the Close node, and the combined string comes out of For Each Close → value at the end. It's the fastest way to see the threading in action - drag the JSON onto the canvas and hit Queue.
Gotchas
- No inputs on the Open node = no iterations, so a loop that "does nothing" usually means the slots are empty, not that Close is broken.
valueis optional. Leave it unconnected for fire-and-forget iteration, but you lose the accumulator and the ordering guarantee.- Match the pair. A For Each Close only accepts
JK_FOREACH_FLOW; keep its Open and Close siblings together or nothing wires up. - Brand-new pack (June 2026, single commit, one author, zero community chatter). The mechanism is the official loop-execution pattern so the foundations are sound, but you're an early adopter - if something odd happens, the source is one short, readable file.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| flow | JK_FOREACH_FLOW | — | |
| valueopt | * | Connect your loop body here so it runs for every item. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| value | * | — |