For Loop Open | akatz-loops
ComfyUI for loops are real now — here's the open half
- initial_value1
- initial_value2
- initial_value3
- initial_value4
- flow_control
- remaining
- value1
- value2
- value3
- value4
For a long time, "loop in ComfyUI" meant a plugin that re-queued the whole workflow, or a hacky feedback wire that ran you out of VRAM. Then the engine grew execution model inversion (ComfyUI PR 2666, the thing that lets a node rebuild its own part of the graph mid-run), and for loops became a native pattern. ForLoopOpen | akatz-loops is the top half of that pattern. It's the node you place when you want to run a region of your workflow N times and carry values across the iterations.
You put the open node on the left, ForLoopClose on the right, and everything wired between them is the loop body - a sampler pass, an image edit, an accumulation of frames. The pair comes from the akatz-ai fork/port of the Deforum loop nodes plus BadCafeCode's execution-inversion demo, and it's the cleanest way I've found to do "run this img2img pass 12 times" without a single custom re-queue script.
How it works
The open node doesn't do much on its own - and that's by design. At execution time it expands itself into an internal WhileLoopOpen via GraphBuilder, and the matching close node re-creates the entire loop body as a fresh subgraph each iteration. That's the "execution inversion" bit: the graph you drew gets copied, rewired, and re-executed under the hood, so each iteration is a real, isolated run rather than state mutating in place.
The inputs and outputs that matter
- remaining (INT, default 1) - how many times the loop runs. This is the one you actually set. Max is 100,000, which is way more than you'll ever want: every iteration is a full re-execution of the body.
- initial_value1 … initial_value4 - four optional pass-through values. Anything you wire in here comes back out each iteration, and you feed the loop's outputs back into the close node to carry state forward (a seed, a latent, an accumulation).
- flow_control (output) - the token you route through the body to the close node. Wire this straight across your loop region; the close node reads it to find where the loop ends.
- remaining (output) - the iteration counter, decremented each pass.
- value1 … value4 (outputs) - the pass-through values, ready to feed the body.
Installing it
ComfyUI Manager is the easy path - search "Akatz-Loop-Nodes" (or the repo name, ComfyUI-Execution-Inversion) and hit install. Manual way:
cd ComfyUI/custom_nodes
git clone https://github.com/akatz-ai/ComfyUI-Execution-Inversion
# restart ComfyUI
The pack's only Python dependency is opencv-python (for the image nodes), and no model files download on install.
Gotchas
The pair only works together - an open node without its close node connected is just a stub. And remaining counts down from your number to zero, so "12" runs 12 times, not 12-plus-one. The classic beginner move is wiring the loop close's output back into the open node's own inputs instead of through the pass-through values; if your values don't seem to change between iterations, check that the body is feeding the close node, not the open node.
One more honest warning: loops multiply execution cost linearly. A 30-step sampler in a 12-iteration loop is 360 sampling steps, and unlike a batch you can't see it coming until the queue fills up. Start with remaining: 2 and watch the console output before you commit to the long run.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| remaining | INT | 10–100000 | — |
| initial_value1opt | * | — | |
| initial_value2opt | * | — | |
| initial_value3opt | * | — | |
| initial_value4opt | * | — |
Outputs (6)
| Name | Type | Description |
|---|---|---|
| flow_control | FLOW_CONTROL | — |
| remaining | INT | — |
| value1 | * | — |
| value2 | * | — |
| value3 | * | — |
| value4 | * | — |