凤希AI - 循环结束(条件)
The node that decides whether there's another pass
- flow
- initial_value0
- 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
- value0
- value1
- value2
- value3
- value4
- value5
- value6
- value7
- value8
- value9
- value10
- value11
- value12
- value13
- value14
- value15
- value16
- value17
- value18
- value19
The engine of the loop
FxAiWhileLoopStart gates a pass. FxAiWhileLoopEnd (凤希AI - 循环结束(条件)) is what actually repeats it - and if you've ever wondered how a node graph manages to loop when the graph is supposed to be a straight line of dependencies, this is the node where the trick is visible.
How it works
When it executes, it looks at condition.
False: it returns the values it was given, unchanged. The loop is over, its outputs are the final state, execution carries on downstream. Nothing dramatic happens.
True: it does something considerably stranger. It walks upstream from its own inputs, collecting every node that contributed - that set is "the loop body". It builds a fresh subgraph containing a copy of each of those nodes, with itself replaced by a special recursive node, folds your initial_value* inputs into the expanded copy of the start node, and returns it as expand. ComfyUI's executor takes that subgraph and runs it, which re-executes the body and arrives back at this node with the new state - where the whole thing happens again if the condition is still true.
That's the entire loop mechanism: no jumps, no stack, just the executor agreeing to run a graph you handed it mid-execution. Depth equals iterations, and one queue press is one run.
It also sweeps the original graph for output nodes whose inputs come from inside the body, so a Save Image sitting in the loop actually saves on every pass instead of only the last.
Inputs and outputs
flow(required) - the loop's tether, from the start node. Everything about the pairing is discovered through this one link; the node also uses it to find the start node inside the cloned subgraph.condition(BOOLEAN, required) - the repeat test. True means "go round again".initial_value0…initial_value19- the state coming out of this pass, twenty slots.
Outputs: value0 … value19 - the state as it leaves the loop.
Slot numbers are the contract: initial_value4 here becomes value4 on the start node in the next pass. Two values travelling means two matched slots; three means three.
Wiring, concretely
- start
flow→ this node'sflow - start
value0..N→ body → this node'sinitial_value0..N(same numbers) - a compare on the carried state → this node's
condition - this node's
value0..N→ whatever happens after the loop
The counter/accumulator pattern is the one you'll write most: carry a total, add to it each pass, compare it to your target, feed the boolean in here. If the loop should also refuse to start when the target is already met, the same compare goes into the start node's condition - it's two sockets for two distinct questions.
Installing
cd ComfyUI/custom_nodes
git clone https://github.com/fxai666/fxai-toolkit
Restart ComfyUI after cloning, or search fxai-toolkit in ComfyUI Manager (publisher fxai). The pack auto-installs soundfile and psutil at import. Nothing to download - the loop nodes are pure graph machinery.
Where it bites
Infinite loops are your responsibility. There is no pass counter hidden in this node. If the condition's inputs never change such that it goes false - because you compared something the body doesn't update, or updated a slot you didn't wire - you get an expanding graph and a long, unhappy run. Wire the state that the compare reads through this node so each pass feeds the next one's judgment.
Orphan nodes don't loop. The body is discovered by walking upstream, so anything in the canvas that doesn't eventually feed an initial_value socket is outside the loop. When someone says "my preview only shows the last iteration", this is usually why - the branch wasn't part of the body at all.
The condition and the state are different things. Passing condition through without changing it means every pass sees the same boolean, which is a very easy accidental infinite loop. The condition must be computed from state the body updates.
Slot mismatch is silent. Mismatched slot numbers on the two ends don't error, they just carry the wrong value around, which is much harder to spot than a crash.
No early exit from inside the body. You can't break out midway; the test happens once per pass, at this node.
Node missing from the menu. This pack imports each node individually inside try/except, logging ❌[凤希AI] 节点加载失败 on the console for any failure - one broken module, one missing node, no loud error. Read the console, restart, then reinstall.
Inputs (22)
| Name | Type | Default | Description |
|---|---|---|---|
| flow | FLOW_CONTROL | — | |
| condition | BOOLEAN | — | |
| initial_value0opt | * | — | |
| 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 (20)
| Name | Type | Description |
|---|---|---|
| value0 | * | — |
| value1 | * | — |
| value2 | * | — |
| value3 | * | — |
| value4 | * | — |
| value5 | * | — |
| value6 | * | — |
| value7 | * | — |
| value8 | * | — |
| value9 | * | — |
| value10 | * | — |
| value11 | * | — |
| value12 | * | — |
| value13 | * | — |
| value14 | * | — |
| value15 | * | — |
| value16 | * | — |
| value17 | * | — |
| value18 | * | — |
| value19 | * | — |