๐ For Loop Start
ComfyUI's for loop is finally usable โ here's the Start half
- initial_value1
- initial_value2
- initial_value3
- initial_value4
- initial_value5
- flow
- index
- value1
- value2
- value3
- value4
- value5
ComfyUI will happily run the same workflow 16 times with batch_count, but that's a shotgun, not a loop: every copy runs independently and starts from the same inputs. If you want iteration where each pass's output feeds the next one - refine a latent until it's good, step a character through poses, do a progressive upscale pass-by-pass - you need an actual loop. The InitialB For Loop is the friendly version of that, and InitialBForLoopStart is its opening brace.
What it actually is
This is the Start half of a two-node loop. You wire For Loop Start into whatever work happens each iteration, then close it with the pack's For Loop End node. The pair re-executes everything between them total times, and each iteration gets a fresh index telling it which pass it's on.
It's worth knowing the trick under the hood, because it explains a couple of the quirks. This node doesn't really "loop" anything itself. It uses ComfyUI's dynamic execution / graph expansion feature (the GraphBuilder machinery) to expand itself into a While Loop Start with an internal counter. The End node later expands into an index-increment plus a "keep going while index < total" check. Net effect: a real for loop, built from the same primitives as a while loop. The practical consequence is that you need a reasonably modern ComfyUI - anything from the 0.2.4 dynamic-execution era (2024) or newer. If your build predates that, the loop nodes won't function, and older versions of the pack just won't work at all.
The inputs that matter
Only one input is actually required: total, the number of iterations (1 to 10000, default 5). That's the entire for-loop contract.
The five initial_value1 through initial_value5 inputs are wildcards - they accept anything. This is how you seed the loop: a seed, a strength, a list, a latent. Each one comes out the matching valueN output and you pass it through the loop body, then back into For Loop End, then into the next iteration. If you've used any state-carrying loop node, this is the same idea.
The outputs you'll actually grab
flow(typeFLOW_CONTROL) - the wire that runs from For Loop Start to For Loop End. It's not data you use; it's the marker that tells ComfyUI what's inside the loop.index(INT) - the current iteration number, 0-based. Sototal=5gives you indices 0, 1, 2, 3, 4. If you're used to counting from 1, that's the first thing that'll trip you up.value1โvalue5- the pass-through values, one per iteration.
How to wire it
The shape is: For Loop Start โ your per-iteration nodes โ For Loop End. Feed index into anything that needs to know which pass this is (a prompt variant, a strength, a filename). To accumulate a result across iterations, run it through the loop body - pass a value into the Start, transform it inside, feed it back through the End, and read the final version off the End node's outputs after the loop finishes.
[ForLoopStart total=5] โ [your nodes] โ [ForLoopEnd]
โโ index, value1..5 value1..5 โโ
Installing it
The pack is called InitialB Util. In ComfyUI Manager, search "InitialB Util" and hit Install, or do it by hand:
cd ComfyUI/custom_nodes
git clone https://github.com/benjiyaya/Comfyui_InitialB_Util
cd Comfyui_InitialB_Util
pip install -r requirements.txt
Then restart ComfyUI. No model downloads, no heavy dependencies - requirements.txt is just torch, numpy, scipy, and Pillow, all of which ComfyUI already ships. One honest warning: the README's own clone URL is still a yourusername placeholder, so if you're cloning by hand, use the real repo above (or just use Manager).
Gotchas
- The loop only re-runs nodes between Start and End. A node that happens to sit inside visually but isn't on the flow wire won't repeat - that confuses everyone once.
indexstarts at 0, not 1.- There's no "break" here. For a bounded number of passes this is fine; if you need to stop early on a condition, that's the While Loop pair's job.
- Intermediate values are gone once the loop exits - the End node only hands back the last iteration's values. If you need every pass's output (say, an image per iteration), save inside the loop body.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| total | INT | 51โ10000 | โ |
| initial_value1opt | * | โ | |
| initial_value2opt | * | โ | |
| initial_value3opt | * | โ | |
| initial_value4opt | * | โ | |
| initial_value5opt | * | โ |
Outputs (7)
| Name | Type | Description |
|---|---|---|
| flow | FLOW_CONTROL | โ |
| index | INT | โ |
| value1 | * | โ |
| value2 | * | โ |
| value3 | * | โ |
| value4 | * | โ |
| value5 | * | โ |