Nodes/WAS Node Suite v3/For Loop Open
ComfyUI Node Runs on cloud

For Loop Open

An actual loop — repeat a slice of the graph N times

By WASasquatch·Created 3 years ago·Updated 4 days ago· 1,844
For Loop Open
  • value_1
  • value_2
  • value_3
  • value_4
  • value_5
  • value_6
  • value_7
  • value_8
  • iterator
  • index
  • metadata
  • value_1
  • value_2
  • value_3
  • value_4
  • value_5
  • value_6
  • value_7
  • value_8
mode
iterations10
total_frames100
max_iterations100
start0

Core ComfyUI is a DAG - data flows one way, no node ever runs twice. That's great for diffusion pipelines and a wall the moment you want to do something n times: process every file in a folder, run a denoise pass ten times carrying state between runs, or step a value through a sequence. WAS For Loop Open is half of the pack's answer - the "repeat this part of the graph" node. Pair it with For Loop Close and the slice of graph between them runs again and again, with values carried forward each iteration.

Its natural partner in crime is WAS Directory Listing: list a folder, wire the paths into this loop's body, and you've just turned "I will type these twenty filenames by hand" into "loop over the directory."

How it works - the mode and the counter

A loop needs to know when to stop, and this node gives you two ways to decide:

  • mode: iterations - runs a fixed count, set with iterations (1 to 10000). The simple, predictable mode.
  • mode: total_frames - runs until For Loop Close has collected total_frames frames. This is the video/animation mode: you don't count loop passes, you count output frames, and the loop keeps going until that pile reaches the target. Two guards keep it sane - max_iterations is a safety limit that stops the loop even if the frame target is never reached, and total_frames mode needs accumulate switched on at the Close end for frames to be collected at all.

Whatever the mode, start sets the first value of index, the loop's counter. Index starts there and counts up by one each iteration - wire it into a Text List Get and you've got "give me entry 0, then entry 1, then entry 2…".

The value slots - how state survives the trip

This is the part that confuses people coming from a normal programming language, because a graph has no variables. The answer is the value slots: value_1 through value_8 on the Open node, mirrored on the Close node. A slot starts with whatever you hand it; inside the loop you read it out, transform it, hand the result to For Loop Close's matching slot; and next iteration For Loop Open's value_1 holds what Close received. That's the loop's state, flowing around the circle. A new slot appears as you wire one, and you can carry anything - images, latents, numbers, text.

The output worth naming: iterator, a WAS_LOOP value that identifies the loop and where it's up to. Wire it straight to For Loop Close's iterator input and nothing else - that connection is what tells Close which Open it belongs to, and it's the one wire you must not improvise with.

Installing it

WAS Node Suite v3: ComfyUI Manager → search WAS Node Suite v3, or clone into custom_nodes, restart. No models, no dependencies.

Two failure modes worth knowing before you queue something ambitious. In total_frames mode, forget to enable accumulate on the Close node and frames are never collected - the loop relies on max_iterations to save you. And remember only nodes wired back to Close re-run each iteration; anything hanging off the Open node outside that loop runs once, which is how you accidentally compute something once and assume it ran n times. Wire the loop body deliberately, and the Open node's index output is your best friend for debugging what iteration you're on.

CategoryWAS Suite/Logic/Loop

Inputs (13)

NameTypeDefaultDescription
modeCOMBOHow the loop decides when to stop; COMBO. 'iterations' runs a fixed count; 'total_frames' runs until For Loop Close has collected total_frames frames.
iterationsINT101–10000Iterations to run in 'iterations' mode; INT, 1 to 10000. Ignored in 'total_frames' mode.
total_framesINT1001–1000000Frames to collect before stopping in 'total_frames' mode; INT. Counted from what For Loop Close collects, which needs accumulate on.
max_iterationsINT1001–10000Safety limit for 'total_frames' mode; INT, 1 to 10000. Stops the loop even when the frame target is never reached.
startINT0-999999–999999First value of index; INT. index counts up by 1 from here each iteration, for reading a position in a list.
value_1optCOMFY_MATCHTYPE_V3The value slot 1 starts with; any type. Read it back out of value_1 and hand the changed one to For Loop Close's value_1.
value_2optCOMFY_MATCHTYPE_V3The value slot {n} starts with; any type. A new slot appears as this one is wired.
value_3optCOMFY_MATCHTYPE_V3The value slot {n} starts with; any type. A new slot appears as this one is wired.
value_4optCOMFY_MATCHTYPE_V3The value slot {n} starts with; any type. A new slot appears as this one is wired.
value_5optCOMFY_MATCHTYPE_V3The value slot {n} starts with; any type. A new slot appears as this one is wired.
value_6optCOMFY_MATCHTYPE_V3The value slot {n} starts with; any type. A new slot appears as this one is wired.
value_7optCOMFY_MATCHTYPE_V3The value slot {n} starts with; any type. A new slot appears as this one is wired.
value_8optCOMFY_MATCHTYPE_V3The value slot {n} starts with; any type. A new slot appears as this one is wired.

Outputs (11)

NameTypeDescription
iteratorWAS_LOOPIdentifies the loop and where it is up to; WAS_LOOP. Wire it straight to For Loop Close's iterator input, and nothing else.
indexINTThe loop's counter; INT. Starts at start and counts up by 1 each iteration, for reading a position in a list.
metadataDICTThis iteration's counters as one value; DICT. Read them with Loop Metadata: current_iteration, index, and the frames collected so far.
value_1COMFY_MATCHTYPE_V3Slot 1 as this iteration receives it; any type. The starting value on iteration 1, then whatever For Loop Close was given last iteration.
value_2COMFY_MATCHTYPE_V3Slot {n} as this iteration receives it; any type.
value_3COMFY_MATCHTYPE_V3Slot {n} as this iteration receives it; any type.
value_4COMFY_MATCHTYPE_V3Slot {n} as this iteration receives it; any type.
value_5COMFY_MATCHTYPE_V3Slot {n} as this iteration receives it; any type.
value_6COMFY_MATCHTYPE_V3Slot {n} as this iteration receives it; any type.
value_7COMFY_MATCHTYPE_V3Slot {n} as this iteration receives it; any type.
value_8COMFY_MATCHTYPE_V3Slot {n} as this iteration receives it; any type.