For Loop Close | Deforum
The other half of the loop, where state comes back around
- flow_control
- initial_value1
- initial_value2
- initial_value3
- initial_value4
- value1
- value2
- value3
- value4
For Loop Close is the bottom of the Deforum loop construct. If For Loop Open | Deforum is "run this N times," the close node is where the loop actually closes: it takes the values your loop body produced, feeds them back into the next iteration, and hands the final results out the bottom once the loop finishes.
You'll almost never use one without the other. The wiring that makes people's heads spin is that the open node's value1–value4 and the close node's initial_value1–initial_value4 are the same variables - seed them at the top, transform them in the body, return them at the bottom, and they come back into the body on the next pass. This is how a Deforum workflow carries a frame counter or a persistent latent through hundreds of iterations.
Inputs and outputs
flow_control- required. TheFLOW_CONTROLsignal from the matchingFor Loop Open. This is what tells the close node which loop it belongs to.initial_value1–initial_value4- optional*inputs: the loop variables coming back from this iteration.- Outputs:
value1–value4- the final values after the loop exits. Anything you need from the loop lives on these wires, which is why you accumulate results rather than try to read mid-loop.
How it works
Like its partner, the close node expands the graph rather than running code in a Python loop. It leans on an internal counter (_ForLoopCounter | Deforum) that decrements remaining each pass and signals when to stop, then recursively re-instantiates the loop body until the counter hits zero. You won't (and shouldn't) wire to that counter directly - it's generated for you.
Gotchas
Keep the body between open and close free of side effects you don't want multiplied - every node in there runs once per iteration by design. And if the loop never terminates, check that something inside is actually decrementing the counter; a body that re-seeds remaining to the same value each pass is the classic accidental infinite loop. In practice, set remaining once on the open node and don't fight it.
Installing it
Part of deforum-comfy-nodes, the official Deforum ComfyUI pack. ComfyUI Manager: search "deforum" (comfyui-deforum), install, restart. Manual:
cd ComfyUI/custom_nodes
git clone https://github.com/deforum-art/deforum-comfy-nodes
Restart ComfyUI after. No extra dependencies or model downloads for this node. Load errors after an upgrade usually trace to an orphaned deforum pip package; pip uninstall deforum and restart clears it.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| flow_control | FLOW_CONTROL | — | |
| initial_value1opt | * | — | |
| initial_value2opt | * | — | |
| initial_value3opt | * | — | |
| initial_value4opt | * | — |
Outputs (4)
| Name | Type | Description |
|---|---|---|
| value1 | * | — |
| value2 | * | — |
| value3 | * | — |
| value4 | * | — |