Nodes/Vantage-NodesV2/For Loop End (VantageV2)
ComfyUI Node

For Loop End (VantageV2)

Where the loop closes and the result comes out

By vantagewithai·Created 15 days ago·Updated 11 days ago· 3
For Loop End (VantageV2)
  • flow
  • value
  • value

Nobody places For Loop End on purpose. You place it because For Loop Start does nothing without it - the pair is the loop, and End is the half that decides when to stop and what to hand back.

What it does

Two inputs, one output. flow is the control socket, wired from the matching For Loop Start's flow. value is an optional wildcard: the body's updated value for this iteration. The output is value - and the only thing that comes out is the value carried by the last completed iteration.

Internally, loops.py counts passes. If the flow says this iteration is the final one (index + 1 >= total), End returns the incoming value and the expansion stops. If not, it rebuilds the body into a new graph with the iteration counter bumped and feeds the incoming value back in as the next initial_value.

That's the whole trick: your body is copied, not re-entered, because ComfyUI's executor is a DAG and has no stack to loop with. The KB's plumbing notes cover why this matters - the engine identifies output nodes and walks backward, re-executing only what changed. Graph expansion is how a pack tells that walk "here's a slightly different graph, again."

The value socket is lazy, and that's load-bearing

The input is declared optional and lazy, and the node only requests it when the flow is active. That's not an optimisation, it's the mechanism: on the last pass it needs the body's output, and it deliberately doesn't pull it earlier than required. The practical upshot for you is just one thing - wire the body's final value into value, and don't leave it dangling expecting the loop to work anyway. An unconnected value gives you None out.

Special case worth bookmarking: total = 0 skips the body entirely and returns the initial value from Start. Handy as a kill switch - zero out the count and the whole body becomes a passthrough.

What loops actually get used for

Because this is a niche in the wider ComfyUI world - "while loop" shows up in sixteen reddit threads across two years, mostly people asking whether it's possible - the honest advice is to keep the body small and the purpose narrow. The cases that survive contact with reality:

  • Iterating a carried accumulator, like building up a long prompt through several refinement passes, or stepping a value by a delta each round.
  • Ladder runs inside one queue item - but note the caching trap: if the body's inputs don't change between passes, the engine may reuse results, so a "loop that samples at five denoises" needs index or value actually feeding the sampler to be genuinely different each time.
  • Post-processing a batch one frame at a time when a downstream node only handles single images.

If what you want is side effects - save each iteration, preview each frame - remember the hard rule from Start: only the dependency path into End's value gets repeated. Put the Save Image where End can see it or it runs once, at the end, with whatever's left.

Install

cd ComfyUI/custom_nodes
git clone https://github.com/vantagewithai/Vantage-NodesV2.git

Restart, hard-refresh, and look under Vantage/Loops. ComfyUI Manager should also install it as Vantage-NodesV2; the clone is the documented path.

No dependencies to install - no requirements file, nothing declared in pyproject.toml. This one is version-sensitive rather than package-sensitive: it needs ComfyUI's graph expansion and lazy evaluation support. An older install imports the pack happily and then fails when it tries to expand.

Troubleshooting

For Loop End requires a For Loop Start - you've wired a While Start's flow into this node. The two flow types share a socket type but the backend checks kind and refuses the mismatch.

Output is None - value is unwired, or the body produced nothing. There's no partial result to inspect; End reports the last carried value or nothing.

Loop stops early - check whether your body's value path actually reaches End. If the connection is missing, the expansion has nothing to carry and the count collapses.

Old node, odd behaviour after an update - create a fresh instance; saved nodes keep the schema they were built with.

CategoryVantage/Loops

Inputs (2)

NameTypeDefaultDescription
flowVANTAGE_LOOP—
valueopt*—

Outputs (1)

NameTypeDescription
value*—