While Loop Open
Loop until the graph says stop
- 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
ComfyUI runs every node once per queue, and that's usually fine - generate, save, done. But the moment your job is "keep refining this until a comparison says it's good, then stop," a single pass stops being enough. That's what the While Loop pair in WAS Node Suite is for, and While Loop Open is the end you drop in first.
You're not going to use this every day. Reach for it when you'd otherwise be re-queueing by hand: iterating a correction until a score or difference crosses a threshold, sampling a list item by item, or building up frames for an animation. If you've seen a For Loop in the same WAS Suite menu and wondered what a while variant adds, it's this: a for loop stops when a count runs out, a while loop stops when a condition you supply says so. Both ship in the pack, and this node is the do-while flavor - the body always runs at least once, because the condition only gets read after an iteration finishes.
How the pair works
While Loop Open and While Loop Close are two halves of one construct, and you build the loop body between them like a sandwich. Open carries up to eight value_1…value_8 slots that hold whatever state the loop needs to move between iterations - an image, a mask, a number, a string, anything. On the first iteration those slots hand out your starting values. You read them, run whatever the body does, and feed the changed results back into the Close node's value inputs. Close sends them around for the next lap.
The wire you can't skip is the iterator output. It's a special WAS_LOOP token, and the tooltip is blunt about it: wire it straight to While Loop Close's iterator input, and nothing else. That one connection tells the Close which loop it belongs to and where it's up to.
The input that actually matters on this end is max_iterations. It defaults to 100 (range 1–10000) and it is your safety valve: a while loop whose condition never turns false would run forever, so this caps it. For a job that should run a fixed number of times, drop it to that number and let the condition be belt and braces.
Two more outputs earn their keep. index is an INT that starts at 0 and ticks up by 1 each iteration - hand it to a Text List Get or a slice node to read the Nth item of a list as you walk it. metadata bundles this iteration's counters into a DICT that the pack's Loop Metadata node knows how to read (current_iteration, index, frames so far).
The gotcha that bites everyone once
Only the graph you wire back through While Loop Close actually re-runs. A node sitting in the body with nothing feeding the Close - say a Save Image whose output nobody uses - runs on the first iteration and then is done, because there's no path telling the engine it belongs to the loop. If you need a step to happen every lap, make sure its output travels through a spare value slot on the way back.
Install
This is part of WAS Node Suite (WASasquatch, MIT, one of the original big ComfyUI packs - running since 2023, over a million downloads). Install once, get hundreds of nodes including this one:
cd ComfyUI/custom_nodes
git clone https://github.com/WASasquatch/was-node-suite-comfyui
or, easier, ComfyUI Manager → search "WAS Node Suite v3" → install, then restart. It needs ComfyUI 0.14.0+ and Python 3.10+, and installs nothing extra on its own. The loop nodes aren't gated behind any feature flag - they're always there. If it won't load right after a fresh ComfyUI update, that's usually a too-new-comfy vs. old-pack moment: pin back to stable or wait a beat for the pack.
Then add While Loop Close, wire the iterator across, and build the body between them.
Inputs (9)
| Name | Type | Default | Description |
|---|---|---|---|
| max_iterations | INT | 1001–10000 | Safety limit; INT, 1 to 10000. Stops the loop even if the condition stays true, so a mistake cannot run forever. |
| value_1opt | COMFY_MATCHTYPE_V3 | The value slot 1 starts with; any type. Read it back out of value_1 and hand the changed one to While Loop Close's value_1. | |
| value_2opt | COMFY_MATCHTYPE_V3 | The value slot {n} starts with; any type. A new slot appears as this one is wired. | |
| value_3opt | COMFY_MATCHTYPE_V3 | The value slot {n} starts with; any type. A new slot appears as this one is wired. | |
| value_4opt | COMFY_MATCHTYPE_V3 | The value slot {n} starts with; any type. A new slot appears as this one is wired. | |
| value_5opt | COMFY_MATCHTYPE_V3 | The value slot {n} starts with; any type. A new slot appears as this one is wired. | |
| value_6opt | COMFY_MATCHTYPE_V3 | The value slot {n} starts with; any type. A new slot appears as this one is wired. | |
| value_7opt | COMFY_MATCHTYPE_V3 | The value slot {n} starts with; any type. A new slot appears as this one is wired. | |
| value_8opt | COMFY_MATCHTYPE_V3 | The value slot {n} starts with; any type. A new slot appears as this one is wired. |
Outputs (11)
| Name | Type | Description |
|---|---|---|
| iterator | WAS_LOOP | Identifies the loop and where it is up to; WAS_LOOP. Wire it straight to While Loop Close's iterator input, and nothing else. |
| index | INT | The loop's counter; INT. Starts at 0 and counts up by 1 each iteration, for reading a position in a list. |
| metadata | DICT | This iteration's counters as one value; DICT. Read them with Loop Metadata: current_iteration, index, and the frames collected so far. |
| value_1 | COMFY_MATCHTYPE_V3 | Slot 1 as this iteration receives it; any type. The starting value on iteration 1, then whatever While Loop Close was given last iteration. |
| value_2 | COMFY_MATCHTYPE_V3 | Slot {n} as this iteration receives it; any type. |
| value_3 | COMFY_MATCHTYPE_V3 | Slot {n} as this iteration receives it; any type. |
| value_4 | COMFY_MATCHTYPE_V3 | Slot {n} as this iteration receives it; any type. |
| value_5 | COMFY_MATCHTYPE_V3 | Slot {n} as this iteration receives it; any type. |
| value_6 | COMFY_MATCHTYPE_V3 | Slot {n} as this iteration receives it; any type. |
| value_7 | COMFY_MATCHTYPE_V3 | Slot {n} as this iteration receives it; any type. |
| value_8 | COMFY_MATCHTYPE_V3 | Slot {n} as this iteration receives it; any type. |