For Loop Start
Actually looping in ComfyUI, the PixNodes way
- initial_value_1
- initial_value_2
- initial_value_3
- initial_value_4
- initial_value_5
- initial_value_6
- initial_value_7
- initial_value_8
- initial_value_9
- initial_value_10
- initial_value_11
- initial_value_12
- initial_value_13
- initial_value_14
- initial_value_15
- initial_value_16
- initial_value_17
- initial_value_18
- initial_value_19
- flow
- index
- value_1
- value_2
- value_3
- value_4
- value_5
- value_6
- value_7
- value_8
- value_9
- value_10
- value_11
- value_12
- value_13
- value_14
- value_15
- value_16
- value_17
- value_18
- value_19
ComfyUI famously doesn't do loops out of the box - every run is one pass through a graph, and if you want to sample five times with different seeds or process ten frames, you're supposed to use the batch system and hope your nodes support it. PixNodes' For Loop Start/For Loop End pair is the escape hatch: real iteration, with state that survives from one pass to the next. This is the start node - the thing that says how many times to loop and what values to carry in.
The one required input is total, the iteration count (1 to 100,000, default 1 - a classic trap, because the default is "run once"). Then there are up to 19 optional initial_value_1 through initial_value_19 slots. These are the loop's carried state: images, numbers, strings, latents, anything. You wire values in here, they travel through the loop body, get modified, and come back in at the end node for the next iteration. The 19-slot design is generous - most loops need two or three.
Outputs are flow (the control handle that must go to the matching For Loop End), index (the current iteration, starting at 0), and value_1 through value_19, which are the current iteration's versions of your carried values. The index output is the secret weapon - you can feed it into a seed or a prompt to make each pass distinct, which is how people do "sample N times with different seeds" without touching the batch system.
How it works under the hood is worth knowing because it explains the weird parts. This isn't a magic loop; the start node builds a while loop out of other PixNodes pieces at execution time using ComfyUI's GraphBuilder - it spawns a Pix_WhileLoopStart, wires the comparison that decides whether to keep going, and the end node closes the loop with Pix_WhileLoopEnd. That's why the pack's changelog has a fix for "loop nodes can't transfer data" (v1.1.0): the whole thing is graph rewriting, and graph rewriting is where the edge cases live. If a loop silently behaves wrong, check that your carried values are actually flowing through - a value you only feed in at start and never bring back through the end is a value that gets recomputed from scratch every pass, not accumulated.
The pattern, concretely:
For Loop Start (total=5)
└─ flow → ... your processing nodes ... → For Loop End (flow)
└─ index → seed input of your sampler
└─ value_1 (e.g. an image) → loop body → initial_value_1 back into For Loop End
Install is the usual PixNodes story: ComfyUI Manager, search PixNodes, install, restart - or:
cd ComfyUI/custom_nodes
git clone https://github.com/pixixai/Comfyui-PixNodes
cd Comfyui-PixNodes
pip install -r requirements.txt
then restart. Requirements are just openai and Requests. No models.
Honest take: loops are powerful and also where ComfyUI graphs get genuinely hard to debug - the KB's plumbing essay is right that the cache and the graph rewriting fight you. Start with total set low, watch index, and don't try to carry 19 values until you've got two working. If it's one thing you remember: the end node is where your processed values must return, or the loop is just re-initializing every pass.
Inputs (20)
| Name | Type | Default | Description |
|---|---|---|---|
| total | INT | 11–100000 | — |
| initial_value_1opt | * | — | |
| initial_value_2opt | * | — | |
| initial_value_3opt | * | — | |
| initial_value_4opt | * | — | |
| initial_value_5opt | * | — | |
| initial_value_6opt | * | — | |
| initial_value_7opt | * | — | |
| initial_value_8opt | * | — | |
| initial_value_9opt | * | — | |
| initial_value_10opt | * | — | |
| initial_value_11opt | * | — | |
| initial_value_12opt | * | — | |
| initial_value_13opt | * | — | |
| initial_value_14opt | * | — | |
| initial_value_15opt | * | — | |
| initial_value_16opt | * | — | |
| initial_value_17opt | * | — | |
| initial_value_18opt | * | — | |
| initial_value_19opt | * | — |
Outputs (21)
| Name | Type | Description |
|---|---|---|
| flow | FLOW_CONTROL | — |
| index | INT | — |
| value_1 | * | — |
| value_2 | * | — |
| value_3 | * | — |
| value_4 | * | — |
| value_5 | * | — |
| value_6 | * | — |
| value_7 | * | — |
| value_8 | * | — |
| value_9 | * | — |
| value_10 | * | — |
| value_11 | * | — |
| value_12 | * | — |
| value_13 | * | — |
| value_14 | * | — |
| value_15 | * | — |
| value_16 | * | — |
| value_17 | * | — |
| value_18 | * | — |
| value_19 | * | — |