๐ While Loop End
The node that actually makes the loop loop
- flow
- initial_value0
- initial_value1
- initial_value2
- initial_value3
- initial_value4
- value0
- value1
- value2
- value3
- value4
The While Loop Start gets the top billing, but it's the End node that does the actual looping. InitialBWhileLoopEnd is where ComfyUI decides whether to run the loop body again, and it's the node that has to do the genuinely clever stuff - recursively re-executing a subgraph until your condition says stop.
What it takes in
Three things, and one of them is easy to get wrong:
flow(required) - theFLOW_CONTROLwire from the matching While Loop Start. This is what tells the End node which loop it's closing.condition(required, and here's the trap: it has no default). This is the exit test. Leave it unwired and the node has nothing to evaluate - it errors. The loop body is supposed to compute this: an index check, a Compare node result, a threshold comparison against the accumulated state.initial_value0throughinitial_value4(optional) - the state coming back out of the loop body each pass.
Outputs are value0 through value4: the state after the loop has finished, which is what you feed into whatever comes after.
How the mechanism actually works
When condition is false, the End node just passes its current values through and the loop exits - done. When condition is true, it does the impressive part: it uses the dynamic execution graph (the same GraphBuilder machinery behind ComfyUI's 0.2.4+ loops) to clone the entire subgraph between the Start and itself, rewire it, and run it again with the new values. That's why the loop works at all - nothing inside ComfyUI natively re-runs, so the End node rebuilds the loop body on every pass.
The practical consequences you'll actually feel:
- Everything that must re-run has to be inside the Start โ End flow. A node that's visually between them but not actually wired into that flow won't be part of the cloned subgraph - it runs once, and its output won't update. When something inside your loop mysteriously stays frozen, that's the first thing to check.
- The loop can't stop itself. It stops when the End node's
conditiongoes false. If your loop body never produces a false, you get an infinite loop. Build the exit condition before the loop body, not after. - The five value channels are the only memory the loop has across iterations. Want to keep a running counter, a running total, an accumulated image? Pass it around the loop, out of the End, and back in.
The two-node pairing
You rarely build a while loop alone. The typical shape:
[WhileLoopStart condition=true] โ [loop body] โ [WhileLoopEnd]
โ values โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
where the loop body ends with something like a Compare node whose result feeds condition. When the compare finally returns false, the End node releases the final value0โ4 downstream and the workflow continues.
Install
Same pack as the rest - InitialB Util. ComfyUI Manager โ search "InitialB Util" โ Install, or clone https://github.com/benjiyaya/Comfyui_InitialB_Util into ComfyUI/custom_nodes/ and pip install -r requirements.txt. No model downloads; all dependencies ship with ComfyUI. Two caveats that apply pack-wide: the README still shows a placeholder clone URL (use the real repo or Manager), and the loop nodes need a ComfyUI with dynamic execution support - update ComfyUI itself if your build predates mid-2024.
Inputs (7)
| Name | Type | Default | Description |
|---|---|---|---|
| flow | FLOW_CONTROL | โ | |
| condition | BOOLEAN | โ | |
| initial_value0opt | * | โ | |
| initial_value1opt | * | โ | |
| initial_value2opt | * | โ | |
| initial_value3opt | * | โ | |
| initial_value4opt | * | โ |
Outputs (5)
| Name | Type | Description |
|---|---|---|
| value0 | * | โ |
| value1 | * | โ |
| value2 | * | โ |
| value3 | * | โ |
| value4 | * | โ |