For Loop Start
A real for loop, or how to stop copy-pasting workflow bodies
- initial_value0
- initial_value1
- initial_value2
- initial_value3
- initial_value4
- initial_value5
- initial_value6
- initial_value7
- initial_value8
- initial_value9
- flow
- index
- value0
- value1
- value2
- value3
- value4
- value5
- value6
- value7
- value8
- value9
ComfyUI doesn't have loops. If you've ever wanted to run the same subgraph ten times with a changing parameter - ten LoRA strengths, ten prompts, ten denoise levels - your options were "copy-paste the nodes" or "hack it with a batch," and neither is fun. For Loop Start is the honest fix: a start node with a count and an index output that increments each pass, paired with For Loop End to close the iteration. It's the cleanest pattern this pack ships, and once it clicks you'll wonder why you ever copy-pasted.
How it works
Set count and every pass through the loop body gets the next index value, from 0 to count−1. You connect your changing parameter to that index output and the loop runs the body that many times. The loop body sits between For Loop Start and For Loop End - anything connected from Start, through your nodes, and back into End gets re-run each iteration with the new index. Values you want to carry across iterations (accumulators, seeds, running results) go in the Start node's initial_value slots, get modified inside the loop, and come back through For Loop End's value slots. On the last pass, For Loop End returns the final values and the loop closes.
Under the hood it's the same graph-expansion trick all ComfyUI loop packs use: the End node asks the executor to expand a copy of the loop body, bumps the index, and repeats until the count is hit. You don't need to care about the mechanics - just know that bigger count equals a bigger expanded graph.
The inputs that matter
count- iterations, 1 to 10000 (required). This is the only one you set on every run.initial_value0…initial_value9- optional pass-through slots, any type. Leave them unconnected unless you're accumulating something across iterations.
Outputs:
flow- connect to For Loop End'sflowinput. Forgetting this is the #1 way to break the loop.index- current iteration, 0 tocount−1. Wire this into whatever changes per pass.value0…value9- the pass-through values for this iteration.
The value slots are dynamic - the pack's JS shows or hides them as you connect things, which keeps the node from being a wall of sockets.
Install
ComfyUI Manager, search "Latent Astronaut Suite," or:
cd ComfyUI/custom_nodes
git clone https://github.com/latentastronaut/comfyui-latent-astronaut-suite
Restart. The loop nodes have no extra dependencies; they run on stock ComfyUI.
Where people get burned
The big one: loops only iterate the subgraph between Start and End. Put a node outside that span and it runs once, not per-iteration - a classic "why is my seed not changing" moment. Also, values you want to use after the loop must come out of For Loop End, not off the loop body's trailing nodes. And remember index starts at 0, so if you want count=5 runs, set it to 5 - the last index you'll see is 4.
Inputs (11)
| Name | Type | Default | Description |
|---|---|---|---|
| count | INT | 11–10000 | Number of iterations |
| initial_value0opt | * | — | |
| initial_value1opt | * | — | |
| initial_value2opt | * | — | |
| initial_value3opt | * | — | |
| initial_value4opt | * | — | |
| initial_value5opt | * | — | |
| initial_value6opt | * | — | |
| initial_value7opt | * | — | |
| initial_value8opt | * | — | |
| initial_value9opt | * | — |
Outputs (12)
| Name | Type | Description |
|---|---|---|
| flow | FOR_LOOP_FLOW | — |
| index | INT | — |
| value0 | * | — |
| value1 | * | — |
| value2 | * | — |
| value3 | * | — |
| value4 | * | — |
| value5 | * | — |
| value6 | * | — |
| value7 | * | — |
| value8 | * | — |
| value9 | * | — |