Nodes/InitialB Util/๐Ÿ” While Loop Start
ComfyUI Node

๐Ÿ” While Loop Start

Run work until it's done, not until a number says so

By benjiyayaยทCreated 6 months agoยทUpdated 6 months agoยท 1
๐Ÿ” While Loop Start
  • initial_value0
  • initial_value1
  • initial_value2
  • initial_value3
  • initial_value4
  • flow
  • value0
  • value1
  • value2
  • value3
  • value4
โ—„conditiontrueโ–บ

For loops answer "how many times?" While loops answer a different question: "keep going until." ComfyUI natively has no answer to either one - batch count just fires the whole graph repeatedly with the same inputs. If you want an iteration where the loop body decides when to stop, the InitialB While Loop pair is the tool, and InitialBWhileLoopStart is the doorway.

What it does

This is the opening node of a while loop. It has one required input, condition (a boolean, default true), plus five wildcard pass-throughs (initial_value0 through initial_value4) that carry state into the loop. Outputs are the flow connection plus value0 through value4.

The wiring is the same shape as the For Loop: While Loop Start โ†’ your body nodes โ†’ While Loop End. But the condition lives on the End node in this pair - whatever the loop body computes decides whether the loop runs again. That's the real difference from the for loop: the exit test is data, not a hardcoded count.

Mechanically, it's ComfyUI's dynamic execution doing the heavy lifting. The Start node just checks the condition: if it's true, the values flow through; if false, it returns an ExecutionBlocker, which is ComfyUI's way of saying "don't run the stuff downstream of this." That's how a false condition skips the loop body entirely - your workflow doesn't error out, it just falls through to whatever comes after the loop.

What's actually useful here

Honestly, the Start node is the boring half. You set the initial condition (usually just true so the loop starts), seed it with whatever state you're iterating on, and let the End node do the thinking. The interesting decision is which loop type you need:

  • For Loop - you know in advance how many passes (frames of an animation, upscale rounds).
  • While Loop - the stopping point depends on the work itself: "keep refining until sharpness โ‰ฅ threshold," "keep generating frames until the total reaches 30," "keep adjusting until the compare says equal."

That second case is where this node earns its keep, because no number of static nodes can express it.

The one real danger

There is no iteration cap on the while loop. The For Loop Start's total is bounded at 10000; a while loop will run until its condition flips false - or forever, if your condition never flips. ComfyUI does let you cancel a run, but a workflow that's spinning in an infinite loop is a workflow that appears frozen. Build your exit condition first, and test with a hard guard if you can (for instance, also checking an iteration counter against a max inside the body).

Installing

The pack is InitialB Util. ComfyUI Manager โ†’ search "InitialB Util" โ†’ Install, or:

cd ComfyUI/custom_nodes
git clone https://github.com/benjiyaya/Comfyui_InitialB_Util
cd Comfyui_InitialB_Util
pip install -r requirements.txt

Restart ComfyUI after. No models to download; requirements.txt is just torch/numpy/scipy/Pillow, all bundled with ComfyUI already. Note the README's clone URL is a yourusername placeholder - clone the real repo above or use Manager. Also: these loop nodes need a ComfyUI with dynamic execution support (anything from the 0.2.4 era, 2024, onward), so if you're on a fossil build, update ComfyUI itself first.

CategoryInitialB/flow/loop

Inputs (6)

NameTypeDefaultDescription
conditionBOOLEANtrueโ€”
initial_value0opt*โ€”
initial_value1opt*โ€”
initial_value2opt*โ€”
initial_value3opt*โ€”
initial_value4opt*โ€”

Outputs (6)

NameTypeDescription
flowFLOW_CONTROLโ€”
value0*โ€”
value1*โ€”
value2*โ€”
value3*โ€”
value4*โ€”