Nodes/ComfyUI Easy Use/While Loop Start
ComfyUI Node Runs on cloud

While Loop Start

Actual loops inside a ComfyUI graph

By yolain·Created 3 years ago·Updated 8 days ago· 2,633
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's graph runs once, top to bottom - which is great until you need to do something repeatedly until a condition is met. Upscale in passes until the image is big enough. Keep regenerating until a check passes. Iterate a value N times. easy whileLoopStart is the front half of Easy-Use's loop construct that makes that possible. It marks where the loop begins; its partner easy whileLoopEnd marks where it circles back.

The README calls this out directly - the pack "supports lazy if else and for loops." This is one of the reasons people reach for Easy-Use in the first place: it brings basic control flow to a graph engine that doesn't natively have it.

How it works

Loops in ComfyUI are faked with a flow-control token. whileLoopStart emits a FLOW_CONTROL signal and passes through your starting values; whileLoopEnd feeds the updated values back around and re-checks the condition. As long as the condition stays true, the body runs again with the new values. When it flips false, execution falls through and continues down the graph. It's "lazy" evaluation under the hood - nodes only re-run when the loop demands it.

The inputs and outputs that matter

  • condition (BOOLEAN, default true) - the gate. While this is true, the loop keeps going. You'll usually drive it from a comparison node (is the width < target? is the counter < N?) rather than leaving it hard-true.
  • initial_value0initial_value19 - up to 20 optional seed values of any type. Whatever you need to carry into the loop and mutate each pass - a latent, an image, a counter, a string.
  • flow (FLOW_CONTROL) out - this must connect to the matching easy whileLoopEnd. It's the wire that makes the loop a loop.
  • value0value19 - the current value of each carried item for this iteration. Wire these into your loop body.

The 20-slot width is deliberate - the pack caps loop inputs/outputs at 20.

How to install it

ComfyUI Manager: search ComfyUI-Easy-Use, install, restart. Manually:

cd ComfyUI/custom_nodes
git clone https://github.com/yolain/ComfyUI-Easy-Use

then install.bat / pip install -r requirements.txt, restart. No models - pure logic.

Common issues & troubleshooting

Infinite loop / ComfyUI hangs. This is the one to respect. If your condition never becomes false, the graph never exits. Always make sure the loop body updates something that eventually flips the condition - increment a counter, shrink a remaining count. A while loop with a permanently-true condition will just spin.

"flow" isn't connected. whileLoopStart and whileLoopEnd are a matched pair. The flow output has to reach the End node or the loop won't form and you'll get an error about the missing flow control.

Node breaks after a ComfyUI update. Loop nodes lean on graph-execution internals, which move between ComfyUI versions - the pack's own changelog repeatedly fixes ifElse and index-switch nodes "failing in certain environments." If loops error right after you updated ComfyUI, update Easy-Use to a matching version before debugging your own graph.

It feels fragile for heavy work. Honest take: graph loops are clever but they're not a general programming language. For a fixed number of passes, easy forLoopStart is simpler and less foot-gun-y than a while loop. Reach for while only when you genuinely can't know the count in advance.

CategoryEasyUse/Logic/While Loop

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*