计次循环尾
The counted-loop tail that re-queues your graph until it's done
- obj
ForEnd (计次循环尾) is the tail end of the pack's simple counted loop: ForStart gives you a counter, you run whatever body you want, and ForEnd decides whether to run it again. "Run this N times" - no condition, no exit check, just a count. That covers a huge amount of real ComfyUI automation: generate 12 variations, process a batch, iterate a refinement pass a set number of times.
It's marked as an output node in the schema, which means ComfyUI treats reaching ForEnd as "the workflow did its job." That matters: put it mid-graph and ComfyUI may consider things complete early. It belongs at the end of the loop.
How it works
The mechanism is worth knowing because it's different from the pack's fancier inner loops. This is the old-school version: ForEnd compares the current iteration count i against total, and if there's still work to do it talks to ComfyUI's own queue API and re-submits the graph with the next i value set - the whole prompt runs again, with the counter nudged forward. That means each iteration is a separate queue entry: you can watch them stack up in the queue, and each pass is independently visible. It also means the loop depends on your ComfyUI's API port being reachable, and it re-runs the entire graph each time rather than just the loop body.
The inputs that matter
- total (INT) - how many iterations in total. Wire this from ForStart's output, or set it directly.
- i (INT) - the current iteration count, wired from ForStart.
- obj (*) - anything you want carried around the loop. It isn't returned (no outputs here - this node ends the loop), but the body reads it per pass.
There are no outputs, and that's by design - this is a terminal node for the loop.
Install and gotchas
The pack install is the usual one:
cd ComfyUI/custom_nodes
git clone https://github.com/yanlang0123/ComfyUI_Lam
and restart. One honest caveat: this older ForEnd implementation predates (and doesn't need) the execution.py patch that the inner-loop nodes require - it works through the queue API instead. That's actually a point in its favor for stability, but it means every iteration costs a full re-queue, and if you close ComfyUI mid-loop, the loop dies with it. If you find yourself looping heavy graphs, that's when the patched ForInnerStart/ForInnerEnd pair earns its keep - it loops in-process without re-queueing the world.
Common issues
- Only one iteration runs - the re-queue didn't take. Check that the queue API is reachable (default port 8188) and that nothing is erroring on the first pass.
- Loop runs but results never vary - the body is re-running with the same seed each pass. Pull the per-iteration seed from ForStart's
seedoutput instead of a fixed seed node. - Queue fills up with your whole loop at once - expected with this design; each iteration is its own job. Cancel the queue to stop it.
For a counted loop that stays inside one queue entry and collects results as it goes, step up to ForInnerStart/ForInnerEnd. For "run exactly N times, don't overthink it," this pair is fine.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| total | INT | — | |
| i | INT | — | |
| obj | * | — |
Outputs (0)
No outputs