ComfyUI Node

For Close

The close brace of your ComfyUI loop — and the secret to accumulating

By jeankassio·Created 2 months ago·Updated 2 months ago· 2
For Close
  • flow
  • value
  • value

In code, a for loop needs a closing brace. In ComfyUI, it needs For Close. If JkForOpen is the opening of the loop from ComfyUI-ForLoops, this node is everything after it: it terminates the loop, decides when it's done, and - here's the part people miss - carries a value from the end of your loop body back to the start of the next iteration.

It's a tiny node on the surface: one flow input, one optional value input, one value output. But it's the brain of the whole thing. Open nodes are dumb counters; the Close node is what actually re-runs your pipeline.

How it works

Under the hood, For Close reads the flow object the Open node handed it, which carries the current iteration index and the total count. If it's the last pass, it just returns its accumulated value and the loop ends. Otherwise it collects every node sitting downstream of the Open node - your whole loop body, including sink nodes like Save Image or Preview - clones them, bumps the counter, and feeds the whole thing back through ComfyUI's graph-expansion engine. Each iteration is literally a fresh copy of your body subgraph, executed in the same Queue Prompt.

That's also why Save Image fires once per iteration without you doing anything clever: the loop deliberately includes output nodes in the repeated region.

Inputs and outputs that matter

  • flow (required) - connect this from For Open → flow. The type is JK_FOR_FLOW, so it will only accept a For loop's flow, not a For Each one. That's on purpose: it stops you from mismatching Open/Close pairs.
  • value (optional) - this is where your loop body plugs in. Connect the end of your pipeline here and two things happen: it forces the whole body to finish before the next iteration starts, and that value gets threaded back into the Open node's initial_value next pass.
  • value (output) - the final accumulated value, emitted once when the loop finishes.

Installing it

Same as the rest of the pack - it's a single install that gives you all four loop nodes:

cd ComfyUI/custom_nodes
git clone https://github.com/jeankassio/ComfyUI-ForLoops

…then restart. Or use ComfyUI Manager and search "ComfyUI-ForLoops". No extra dependencies, no model downloads, nothing else to set up.

A common, robust pattern

The README's recommended wiring:

For Open flow ─────────────────► For Close flow
For Open index ─► [ load line → generate → Save Image ] ─► For Close value

Note the loop body's result going into For Close value even if you don't care about the result. That connection guarantees ordering - the next iteration can't start until the body is finished. Without it, the loop can race ahead of work that hasn't completed yet. For accumulating something across iterations (say, concatenating per-item text, or carrying a best-so-far result), that same wire is what feeds the next round's initial_value.

Gotchas

  • A For Close with no Open is a dangling node. It needs a flow of the matching type or it's dead weight.
  • value is optional. If you just want the loop to run and don't care about results, leave it unconnected - but you lose the ordering guarantee.
  • The pack is brand new (first commit June 2026, one author, zero community discussion). The mechanism is the official graph-expansion pattern, so it's more trustworthy than its age suggests, but if something's off there's no crowd of forum posts to bail you out - check the source, it's one readable file.
CategoryJkNodes

Inputs (2)

NameTypeDefaultDescription
flowJK_FOR_FLOW
valueopt*Connect your loop body here so it runs every iteration. Its value is threaded back into For Open and returned when the loop ends.

Outputs (1)

NameTypeDescription
value*