ComfyUI Node

flow_forStart

A real for-loop primitive for ComfyUI graphs

By cardenluo·Created 2 years ago·Updated 22 days ago· 309
flow_forStart
  • 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
  • index
  • 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
total1

ComfyUI's execution model runs a graph once per queue, which is why "looping" in the wild is usually people either re-queuing the same prompt over and over by hand or building a detection-and-crop loop like Impact Pack's detailers. flow_forStart and its partner flow_forEnd are Apt_Preset's attempt at a general-purpose for-loop primitive you drop into any graph: set a count, wire up your starting values, and everything between the two nodes re-executes for each iteration.

How it works

total is your loop count - how many iterations to run, up to 100,000. flow_forStart outputs a flow socket typed FLOW_CL, and that's the mechanism that actually makes looping happen: wire it to the matching flow input on a flow_forEnd node placed after the subgraph you want repeated, and that FLOW_CL connection is what tells ComfyUI's execution engine to keep re-triggering everything in between instead of running it once and moving on. Alongside flow, flow_forStart also outputs index - the current iteration count - and up to 19 value_1 through value_19 slots, seeded from the matching initial_value_119 optional inputs, that carry your working values through each pass of the loop. flow_forEnd collects whatever you route back into its own initial_value_119 slots at the end of each iteration and emits the final results.

The 19-slot pattern is a pragmatic (if slightly clunky) way of handling "however many values your loop body needs to carry" without a generic list type - wire only as many of the value_N slots as you actually use.

Inputs and output

  • total (INT, required, default 1, max 100,000) - iteration count.
  • initial_value_1initial_value_19 (optional, wildcard) - starting values for whatever your loop body needs to track.
  • flow (FLOW_CL, output) - wire this to flow_forEnd's flow input; this is what closes the loop.
  • index (INT, output) - current iteration number, for use inside the loop body.
  • value_1value_19 (outputs, wildcard) - pass-through of your initial values into the loop body.

Installing it

Search ComfyUI-Apt_Preset in ComfyUI Manager and install, or manually: cd ComfyUI/custom_nodes && git clone https://github.com/cardenluo/ComfyUI-Apt_Preset.git, then restart. The README's own dependency step is "double-click install.bat" - a Windows-first instruction, with no requirements.txt documented elsewhere, so on Linux/Mac open that file to see what it installs and mirror it by hand in your ComfyUI venv. This node is pure control flow and needs none of the pack's optional extras (GGUF, Advanced-ControlNet, nunchaku, downloaded models).

Common issues

The one that will actually stop you cold: flow_forStart on its own does nothing. It needs a matching flow_forEnd downstream with its flow output wired into flow_forEnd's flow input, or ComfyUI has no reason to re-execute anything between them. If your loop only ever runs once, check that connection first.

Because total allows up to 100,000, be deliberate about it - every iteration re-runs everything wired inside the loop body, so if that includes a sampler or anything GPU-bound, a typo in total can turn a quick test into a very long, very expensive run. Start small and confirm the loop is behaving before scaling up.

And the pack-wide caveat: this is one node in a large, actively developed package, and an import failure elsewhere in the pack can take this node down too. If it's missing after install, check the ComfyUI console log at boot for the real traceback.

CategoryApt_Preset/flow

Inputs (20)

NameTypeDefaultDescription
totalINT11–100000
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
indexINT
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*