While Loop Start (VantageV2)
Enter the loop — and never forget the exit
- initial_value
- flow
- index
- value
A for loop knows how many passes it gets. A while loop doesn't - it keeps going until the body reports it's done, which is more flexible and considerably more dangerous. ComfyUI has no stack to blow, but it can absolutely queue forever.
Inputs and outputs
condition is a BOOLEAN, default True, and it decides whether the body is entered at all. If it's False at the start, the body is skipped and the initial value comes straight back out. That's your guard clause - use it.
initial_value is an optional wildcard: what the body receives on the first pass.
The three outputs mirror For Loop Start exactly. flow goes to the matching While Loop End and nowhere else, index is the current zero-based pass count, value is the carried value - initial_value on pass 0, then the previous pass's result.
The mechanism, and the thing people get wrong
Same as the For pair: this is graph expansion, not a Python loop. Start hands the engine a VANTAGE_LOOP flow record; While Loop End copies the body's dependency path into a new graph each pass and re-submits it with the carried value and an incremented index.
The difference is where the exit condition lives. In a for loop, total on Start decides everything. Here, Start's condition only decides whether to enter. After that, While Loop End checks a computed boolean every pass and continues while it's True. So the condition you wire into Start is a completely different value from the one you wire into End, and you need both:
- Start's
condition: your guard - is there anything to do? Wire it from something real, or leave it True if the body should always run once. - End's
condition: the updated truth - should we go round again?
That second one must be a function of the carried value. The moment it stops depending on value, you've written an infinite loop, because the body will return the same result forever and the expansion will keep obliging. ComfyUI will not save you; you'll be pressing Cancel and reading the queue.
What it's genuinely good for
Convergence-ish work: keep refining until a threshold is crossed, or keep stepping until a counter exceeds a limit computed from the input rather than fixed in advance. The reddit corpus is thin here - "while loop" appears in sixteen threads over two years, and mostly as people asking whether ComfyUI can do this at all - so treat loops as a specialist tool rather than something to reach for casually.
And keep the side-effect warning in mind, because it's the same for both loop types: only the path from Start to While Loop End's value is repeated. A Save Image or Preview sitting in the body but not feeding End runs once, not per iteration. If you want per-pass output, it has to be in the closure.
Install
cd ComfyUI/custom_nodes
git clone https://github.com/vantagewithai/Vantage-NodesV2.git
Restart, hard-refresh the browser, find it under Vantage/Loops, or search "While Loop Start". ComfyUI Manager should also carry Vantage-NodesV2; the clone is the documented route.
No pip install - no requirements file, no declared dependencies, all imports come from ComfyUI. It's a version requirement, not a package one: the node needs ComfyUI's graph expansion API and lazy input evaluation. An older install will load the pack and then error when it tries to expand.
Troubleshooting
Body skipped entirely. Start's condition is False. It defaults to True, so if you wired something in, check what it evaluates to on the first pass.
Runs forever. End's condition isn't changing. It has to be derived from the outgoing value and eventually go False. Stop the queue manually and fix the comparison; nothing in the node will break the cycle for you.
Wrong loop type error. You've wired a For Start into a While End, or the reverse - the backend rejects the mismatch.
Nothing carried out. End's value isn't wired, or the body's result never reaches it.
And after a pack update, if the node's sockets look stale, place a fresh instance; saved nodes keep their original schema.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| condition | BOOLEAN | true | — |
| initial_valueopt | * | — |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| flow | VANTAGE_LOOP | — |
| index | INT | — |
| value | * | — |