凤希AI - 循环开始(计数)
Run the same subgraph N times without pasting it N times
- initial_value1
- initial_value2
- initial_value3
- initial_value4
- initial_value5
- initial_value6
- initial_value7
- initial_value8
- initial_value9
- initial_value10
- initial_value11
- initial_value12
- initial_value13
- initial_value14
- initial_value15
- initial_value16
- initial_value17
- initial_value18
- initial_value19
- flow
- index
- value1
- value2
- value3
- value4
- value5
- value6
- value7
- value8
- value9
- value10
- value11
- value12
- value13
- value14
- value15
- value16
- value17
- value18
- value19
The problem it solves
ComfyUI has no "repeat this 40 times" button. If you have a 40-segment video and each segment needs the same face-refine-then-upscale-then-save chain, the native answer is to copy that chain 40 times, or to queue the workflow 40 times and re-edit the index each time. Both are miserable.
FxAiForLoopStart (凤希AI - 循环开始(计数)) is the top half of a loop pair. You put your body between the start node and FxAiForLoopEnd, set how many times you want it to run, and ComfyUI executes the body once per iteration - as one run, one queue entry, one progress bar.
How the loop actually works
This is the part worth understanding, because it explains every quirk later. ComfyUI's execution engine has no goto. What it does have is this: a node can return {"result": ..., "expand": <subgraph>}, and the executor hangs that subgraph onto the current run and keeps going. That's it. That's the loop primitive.
So a "for loop" here is a counted while loop built out of graph expansion. FxAiForLoopStart emits a small subgraph containing a FxAiWhileLoopStart proxy, and hands back the current state plus an index. FxAiForLoopEnd then wraps FxAiWhileLoopEnd with a condition of its own making - literally index + 1 < total - and the while-end clones the body, folds the new state into the start node, and recurses. Depth of the expansion equals the number of iterations, and the recursion lives in ComfyUI's executor rather than the Python stack. Which is why a 500-iteration loop doesn't blow up.
Inputs and outputs
Required: total - the iteration count. 0 to 100000, default 1. The author's tooltip is exact about the zero case: it runs the body zero times, the save nodes inside it don't fire, and the end node passes its own inputs straight out. That's a working "disable" switch, not a crash.
Optional: initial_value1 through initial_value19. These are the loop's seed values - the state you start from. The sockets are wildcards, so whatever type goes in comes back out.
Outputs: flow (wire it to the end node), index (INT, counts from 0), and value1 … value19, which are the current values of your state. You wire those into your body. On the first pass they're your seeds; on later passes they're whatever the previous iteration fed back into the end node. Slot numbers pair up - initial_value3 on the end becomes value3 on the next pass - so if two things need to travel between iterations, they need two slots and matching numbers on both nodes.
The frontend only shows the slots you're actually using; the last empty one grows a new socket when you connect it. The labels are Chinese (循环体 for flow, 序号 for index, 初始值 in, 过程值 out), so don't be thrown when the canvas doesn't match the node's English class name.
A loop you'd actually build
Take the video segment workflow: FxAiVideoSegmenterV1 gives you 分段总数, this node's total takes it, index goes into FxAiVideoSegmentLoad's 当前索引, and the segment list plus path travel through slots so each iteration sees the same source. Twenty lines of graph replace twenty copies of your pipeline, and you can change the resolution of every segment at once.
Wire it as: start flow → end flow; start valueN → body → end initial_valueN; end valueN → whatever consumes the final result.
Installing
cd ComfyUI/custom_nodes
git clone https://github.com/fxai666/fxai-toolkit
Restart ComfyUI, or grab it via ComfyUI Manager by searching fxai-toolkit (registry publisher fxai). The pack pip-installs soundfile and psutil on first import. No models required for the loop nodes.
The README and workflows are Chinese-language, and there's no alias layer for node names - a loop node from another pack, or an older fxai build, won't resolve.
Where it bites
The body has to be attached to the loop, not just nearby. On the way back round, the end node finds the body by walking upstream from its own initial_value* inputs. Anything floating in the canvas that doesn't feed the end node simply isn't part of the loop, and won't re-run. Save nodes are handled - the pack attaches output nodes reachable from the body - but a branch that never lands on an initial_value socket isn't in the loop at all.
Nothing runs if you forget flow. The end node reads its start node's total by following flow, and raises flow 接的不是循环开始节点 if you've wired a while-start into a for-end. The pairs look identical, which is why cross-wiring is the most common mistake.
Iteration count is a real budget. Each pass is another graph expansion held for the run. Twenty segments is fine. A thousand is how you find out what your swap file is for, and a crash mid-run loses everything that wasn't already saved to disk.
There's no early exit. It counts, it doesn't judge. If you need "keep going until the thing is good", that's the condition pair, or a FxAiCompare feeding the while nodes.
Inputs (21)
| Name | Type | Default | Description |
|---|---|---|---|
| total | INT | 10–100000 | 循环次数。0 = 一次都不跑,循环体(含里面的保存节点)全部不执行,结束节点直接把下面的初值原样输出。 |
| start_index | INT | 0-1000000–1000000 | 开始索引,序号的起点。序号 = 开始索引 + 第几轮(第一轮就是开始索引本身)。 循环次数只决定跑几轮,不受开始索引影响。 |
| initial_value1opt | * | — | |
| initial_value2opt | * | — | |
| initial_value3opt | * | — | |
| initial_value4opt | * | — | |
| initial_value5opt | * | — | |
| initial_value6opt | * | — | |
| initial_value7opt | * | — | |
| initial_value8opt | * | — | |
| initial_value9opt | * | — | |
| initial_value10opt | * | — | |
| initial_value11opt | * | — | |
| initial_value12opt | * | — | |
| initial_value13opt | * | — | |
| initial_value14opt | * | — | |
| initial_value15opt | * | — | |
| initial_value16opt | * | — | |
| initial_value17opt | * | — | |
| initial_value18opt | * | — | |
| initial_value19opt | * | — |
Outputs (21)
| Name | Type | Description |
|---|---|---|
| flow | FLOW_CONTROL | — |
| index | INT | — |
| value1 | * | — |
| value2 | * | — |
| value3 | * | — |
| value4 | * | — |
| value5 | * | — |
| value6 | * | — |
| value7 | * | — |
| value8 | * | — |
| value9 | * | — |
| value10 | * | — |
| value11 | * | — |
| value12 | * | — |
| value13 | * | — |
| value14 | * | — |
| value15 | * | — |
| value16 | * | — |
| value17 | * | — |
| value18 | * | — |
| value19 | * | — |