For Loop Open | Deforum
The loop that runs your animation N times
- initial_value1
- initial_value2
- initial_value3
- initial_value4
- flow_control
- remaining
- value1
- value2
- value3
- value4
Deforum is an animation toolkit, and animation means "do roughly the same thing hundreds of times, once per frame." That's what the For Loop Open / For Loop Close pair is for: a real looping construct in a graph language that doesn't natively have one. This node is the top of the loop - you set how many iterations you want and declare what data flows into each pass, and its sibling For Loop Close closes the circle.
The headline number is remaining: an INT (default 1, up to 100000) that says how many more iterations the loop will run. In a Deforum workflow that's your frame count - set it to 120 and the loop body runs 120 times.
What it outputs
flow_control- theFLOW_CONTROLtoken that wires intoFor Loop Close. This is the engine signal that makes the loop happen; it's not data, it's control flow, and it has no value beyond closing the loop.remaining- anINTcounting down as iterations pass. Handy for branching inside the body ("on the last frame, do something special").value1–value4- up to four*values carried into each iteration. These are your loop variables: a frame counter, a prompt, a latent to build on.
On the input side, initial_value1–initial_value4 let you seed those values for the first pass. The loop pattern is: seed initial values in the open node, transform them inside the body, feed the results back through the close node, and they come back into the next iteration automatically.
How it actually works
Under the hood the open node doesn't "loop" anything itself - it expands (via ComfyUI's GraphBuilder) into a While Loop Open, and the matching close node wires in the internal _ForLoopCounter that counts the iterations down. The graph literally re-instantiates the loop body for each iteration - that's why loop bodies feel a bit magical: ComfyUI rebuilds the nodes between passes. The practical upshot: anything inside the open/close pair runs once per iteration, and values threaded through the close node carry state between passes.
Gotchas
Loop bodies are re-expanded per iteration, so keep the body minimal or graph building gets slow. And if your loop is long, accumulate per-iteration results with Accumulate | Deforum rather than trying to read values out mid-loop - read after close.
Installing it
Ships in deforum-comfy-nodes, the official Deforum ComfyUI pack. ComfyUI Manager: search "deforum" (comfyui-deforum), install, restart. Or:
cd ComfyUI/custom_nodes
git clone https://github.com/deforum-art/deforum-comfy-nodes
Restart ComfyUI after. No extra pip packages or models for this node. Known hiccup on upgrades: an orphaned deforum pip package; pip uninstall deforum and restart.
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 | * | — |