Nodes/ComfyUI-Apt_Preset/flow_whileStart
ComfyUI Node

flow_whileStart

Faking a while-loop inside a graph that isn't supposed to have one

By cardenluo·Created 2 years ago·Updated 22 days ago· 309
flow_whileStart
  • initial_value_0
  • initial_value_1
  • initial_value_2
  • initial_value_3
  • initial_value_4
  • initial_value_5
  • initial_value_6
  • initial_value_7
  • initial_value_8
  • initial_value_9
  • initial_value_10
  • initial_value_11
  • initial_value_12
  • initial_value_13
  • initial_value_14
  • initial_value_15
  • initial_value_16
  • initial_value_17
  • initial_value_18
  • initial_value_19
  • flow
  • value_0
  • value_1
  • value_2
  • value_3
  • value_4
  • value_5
  • value_6
  • value_7
  • value_8
  • value_9
  • value_10
  • value_11
  • value_12
  • value_13
  • value_14
  • value_15
  • value_16
  • value_17
  • value_18
  • value_19
conditiontrue

ComfyUI's graph is a DAG - nodes run once, in order, no going back. That's fine right up until you need to repeat something: refine an image until it's sharp enough, keep upscaling until you clear a target resolution, run a couple of correction passes on the same latent. flow_whileStart is one half of Apt_Preset's answer to that gap. Pair it with flow_whileEnd and you get something that behaves like a while-loop sitting inside an otherwise loop-free graph.

How it works

flow_whileStart is where the loop begins. It takes a condition (a plain boolean, defaulting to true) and up to twenty initial_value slots of any type - images, latents, numbers, strings, whatever your loop body needs to carry forward between passes. It emits a flow output (type FLOW_CL, Apt_Preset's own private token - it only talks to this pack's own nodes) plus the same twenty value slots passed through unchanged on the first lap. Wire flow into whatever nodes make up your loop body, feed the results into flow_whileEnd, and if its condition is still true it feeds updated values back through the same numbered slots for another round. Stop condition flips false, the loop ends.

Under the hood this is the standard trick every for/while pack in the ComfyUI ecosystem uses to fake iteration on a graph that has no native back-edges: rather than a real loop, the End node re-triggers execution of everything between Start and End, feeding each output back in as the next round's input, until the condition goes false. It's not free - each pass is a genuine execution, not a cheap increment - but it's the closest thing to a loop ComfyUI has without dropping into the API and a Python script.

The inputs and outputs that matter

  • condition - the only thing you touch directly here. Defaults to true, so by default the loop always starts; wire something else in only if you sometimes want to skip the loop body entirely.
  • initial_value_0initial_value_19 - twenty typed-* slots. Wire in whatever state your loop needs on lap one: a starting image, a counter at 0, an empty string. You don't have to use all twenty.
  • Output: flow (into your loop body and eventually flow_whileEnd), plus value_0value_19, mirroring whatever you plugged into the matching initial_value slots.

How to install it

Via ComfyUI Manager: search ComfyUI-Apt_Preset (or just "Apt_Preset"), install, restart. Manually:

cd ComfyUI/custom_nodes
git clone https://github.com/cardenluo/ComfyUI-Apt_Preset.git

Then install dependencies - on Windows, double-click install.bat inside the cloned folder; on Linux/Mac there's no equivalent script, so activate your ComfyUI venv and run pip install -r ComfyUI-Apt_Preset/requirements.txt yourself. Restart ComfyUI either way. Nothing to download model-wise for this node - it's pure control-flow plumbing - though the pack's requirements.txt is heavier than you'd expect for that (pandas, gguf, onnxruntime, transparent-background, scenedetect…) because Apt_Preset is one big monolithic pack covering GGUF loading, audio, video and mesh tools too, not just flow control. Installing pulls all of it in regardless. For context: the pack sits around 300 GitHub stars, MIT-licensed, and updates every few weeks - a solid, actively maintained personal productivity pack, not a top-tier ecosystem player.

Common issues & troubleshooting

Slot numbers have to match on both ends. initial_value_3 on Start and value_3 on End are the same variable across iterations - mix up the numbering between the two nodes and your loop body silently gets fed the wrong thing next lap. Keep it consistent front to back.

Nothing stops a bad condition. There's no built-in iteration cap in the schema - if your condition never flips false, you'll hang the queue. Wire your own counter through one of the value slots and compare it against a limit inside the loop body if you're not certain the condition resolves.

This is for a handful of in-graph iterations, not mass-producing variations. When people on r/comfyui ask how to run the same block twenty times with different LoRAs or prompts, the answers that actually stick are the ComfyUI API plus a script, or a purpose-built custom node - loop-node pairs like this one come up too, but mostly for bounded repetition inside one run (repeat until sharp enough, repeat N fixed times), not for driving a big batch of unrelated generations.

A dependency failure anywhere in Apt_Preset can hide this node too. The whole pack registers from one Python module, so a broken import elsewhere in requirements.txt can knock every node off the list, flow control included - check the console for import errors before assuming flow_whileStart itself is broken.

CategoryApt_Preset/flow

Inputs (21)

NameTypeDefaultDescription
conditionBOOLEANtrue
initial_value_0opt*
initial_value_1opt*
initial_value_2opt*
initial_value_3opt*
initial_value_4opt*
initial_value_5opt*
initial_value_6opt*
initial_value_7opt*
initial_value_8opt*
initial_value_9opt*
initial_value_10opt*
initial_value_11opt*
initial_value_12opt*
initial_value_13opt*
initial_value_14opt*
initial_value_15opt*
initial_value_16opt*
initial_value_17opt*
initial_value_18opt*
initial_value_19opt*

Outputs (21)

NameTypeDescription
flowFLOW_CL
value_0*
value_1*
value_2*
value_3*
value_4*
value_5*
value_6*
value_7*
value_8*
value_9*
value_10*
value_11*
value_12*
value_13*
value_14*
value_15*
value_16*
value_17*
value_18*
value_19*