Nodes/yiu_comfy_nodes/.internal/while_loop_start
ComfyUI Node

.internal/while_loop_start

The hidden open-bracket of ComfyUI's while-loop

By leizingyiu·Created about a year ago·Updated 3 months ago· 1
.internal/while_loop_start
  • 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
  • flow
  • value0
  • value1
  • value2
  • value3
  • value4
  • value5
  • value6
  • value7
  • value8
  • value9
  • value10
  • value11
  • value12
  • value13
  • value14
  • value15
  • value16
  • value17
  • value18
  • value19
conditiontrue

ComfyUI has no native for/while construct - graphs are acyclic. The workaround is dynamic graph expansion: a node rebuilds a chunk of the graph at runtime, re-executing it with new values until a condition says stop. That's what this pack's loop machinery does, and __y_i_u__while_loop_start is the open bracket of that loop: it declares the loop's initial values and emits a flow token that drives the iteration.

It's an .internal node, hidden from the menu by the pack's front-end code. You'll rarely add it yourself - it lives in saved workflows, most visibly paired with the upscale loop's START/END pair, where the machinery writes loop-carried state (the step index, the working image) back into this node each pass.

The design is deliberately generic: one condition boolean and up to 20 loop-carried values, passed through as initial_value0 through initial_value19. On the first pass, those carry your starting values; on later passes, the loop-end node writes the updated values back in. When the condition is false, the node stops the loop by emitting an execution blocker instead of values, which is how a graph with no native loop terminates cleanly.

Inputs

  • condition - BOOLEAN, default true. Whether to run the body.
  • initial_value0 … initial_value19 - optional, any type. The loop's carried state.

Outputs

flow - the FLOW_CONTROL token that drives the loop, and value0 … value19, the current iteration's values.

Installing it

Part of yiu_comfy_nodes by leizingyiu:

cd ComfyUI/custom_nodes
git clone https://github.com/leizingyiu/yiu_comfy_nodes

restart ComfyUI. No extra dependencies.

Where people get burned

  • It's hidden, and that's fine. Don't hunt for it in the menu. If you're building a loop by hand, you're more likely to use the ready-made yiuUpscaleLoopStart/END pair, which drives this machinery for you.
  • Unconnected optional values are just None. Pass only the slots you use; leaving a gap is not an error.
  • The condition defaults to true. An unwired condition means "loop forever" - the termination has to come from the loop-end side (the pack's loop always wires it), so don't expect a safety net if you construct this by hand.
  • Requires dynamic-graph ComfyUI. If your install predates GraphBuilder support, the loop it powers errors out. Update before debugging anything else.
Category_yiu_nodes/internal

Inputs (21)

NameTypeDefaultDescription
conditionBOOLEANtrue
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 (21)

NameTypeDescription
flowFLOW_CONTROL
value0*
value1*
value2*
value3*
value4*
value5*
value6*
value7*
value8*
value9*
value10*
value11*
value12*
value13*
value14*
value15*
value16*
value17*
value18*
value19*