While Loop End (VantageV2)
The node that decides whether you go round again
- flow
- value
- value
A while loop exists because you don't know the pass count up front - and this node holds the answer. Get its condition wrong one way and the body runs once; wrong the other way and you're cancelling a queue.
What it does
flow takes the control socket from the matching While Loop Start. value is an optional wildcard - the body's updated result for this pass. condition is a BOOLEAN, default False, whose tooltip says exactly what it does: "Continue with another iteration when true."
So the default behaviour is: run the body once, stop. That's a sensible default for a node that could otherwise spin, and it's also the first thing to check when someone says their while loop isn't looping. It checked condition, saw False, and returned.
The single output is value, the carried value from the last pass - which is what you'll wire onward into whatever needed the accumulated result.
How a pass resolves
The loop is graph expansion, not a Python while. Start produces a flow record; While Loop End takes the dependency path from Start to itself, copies it into a fresh graph for the next pass, and re-submits with the carried value. The order per iteration matters:
- Body executes with the current
value. - End receives the new
valueand the computedcondition. conditionTrue → expand another pass. False → return the current value.
Which means the body always runs at least once if Start let it in - the exit condition is never checked before the work. An expensive body with a condition that's about to be False still costs one full pass. If that's unacceptable, guard on Start, not here.
Wiring it so it terminates
The condition input has to be computed from the outgoing value - that's the only guarantee you have. Practical shape: body takes value N, returns N+1, and a comparison node also returns N < 5 (or a threshold check on the accumulated result). Wire the number to value and the boolean to condition. When the comparison flips, End stops.
The failure mode is subtle and worth naming: if condition is a static widget left on True, or comes from a branch that doesn't read value, the condition is identical every pass. Identical condition means identical next pass, forever. Nothing in the pack detects that for you. Watch the queue and be ready to cancel.
If you need a hard ceiling as well - loop until converged or 10 passes, whichever first - you can't express that in this node alone. Fold it into the condition computation: continue = still_improving AND index < 10, with index coming off Start. That's a deliberate design, and it's the standard way people build the safety net.
Nothing here has a stack to blow, so a runaway loop won't crash - it'll just take hours. Set ceilings.
Where it's worth the complexity
While loops are a specialist taste - "while loop" appears in sixteen reddit threads across two years, mostly as "can ComfyUI even do this". Batch work, prompt queues and AnimateDiff frame batches cover the ordinary cases. Reach here when the iteration count is data-dependent: refine until a score passes, step a strength up until the mask covers the region.
And keep the closure rule in mind - only the path into End's value repeats. A Preview or Save Image sitting in the body but outside that path will run once, at the end. Per-iteration output has to be part of the loop's dependency path.
Install
cd ComfyUI/custom_nodes
git clone https://github.com/vantagewithai/Vantage-NodesV2.git
Restart ComfyUI, hard-refresh, then find it under Vantage/Loops. ComfyUI Manager should also list Vantage-NodesV2; the git clone is the documented path.
Nothing to pip install - no requirements file, no declared dependencies, and it runs on ComfyUI's own stack. What it does need is a recent ComfyUI with graph expansion and lazy input evaluation. On an older install the pack imports fine and then throws when it tries to expand the loop, which looks like a broken pack rather than an out-of-date ComfyUI.
Troubleshooting
One pass, then done. condition is still False, either because you never wired it or because the comparison got a value you didn't expect. Its default is genuinely False.
It never stops. See above: make condition a function of value, and add a count ceiling so a stuck comparison costs you ten passes instead of the evening.
While Loop End requires a While Loop Start. The flow came from a For Start. The kinds are checked at execution.
None out. End's value is unwired - nothing to carry, nothing to return. And after a pack update, if the sockets look stale, drop a fresh instance; saved nodes keep their original schema.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| flow | VANTAGE_LOOP | — | |
| condition | BOOLEAN | false | Continue with another iteration when true. |
| valueopt | * | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| value | * | — |