Nodes/WAS Node Suite v3/While Loop Close
ComfyUI Node Runs on cloud

While Loop Close

Where a ComfyUI while loop actually decides to stop

By WASasquatch·Created 3 years ago·Updated 4 days ago· 1,844
While Loop Close
  • iterator
  • continue_loop
  • value_1
  • value_2
  • value_3
  • value_4
  • value_5
  • value_6
  • value_7
  • value_8
  • metadata
  • value_1
  • value_2
  • value_3
  • value_4
  • value_5
  • value_6
  • value_7
  • value_8
accumulatefalse

The While Loop Close node is where the iteration ends and the loop decides whether there's going to be another one. If you've got the WAS Node Suite loaded and a While Loop Open on the canvas, this is the node you glue to the other side of your loop body - it finishes one lap, checks your stop condition, and either wraps back around or hands you the results.

Think of it as the do-while keyword from every language you've ever used. The body always executes at least once, because the condition isn't read until an iteration has finished. That ordering is the whole reason the loop is shaped this way: ComfyUI can't "peek" at a condition before anything has run, so it runs a lap and then asks.

The inputs that run the show

  • iterator - the WAS_LOOP token from While Loop Open. Wire it across, don't touch it again.
  • continue_loop - the condition. It takes a BOOLEAN, or a NUMBER where any non-zero value means true. This is read after each iteration, and it's what makes the loop while. Feed it from Logic Compare Numbers, Text Compare, or any logic node that answers true/false. Wire it to false (or leave it) and the loop runs its body once, then stops.
  • accumulate - the collector. Off by default: each value output holds only the last thing that slot saw. Tick it on and every value output carries everything that slot received - batched into one for images, masks and latents (i.e. frames), and into a LIST for everything else.
  • value_1value_8 - the state slots coming back from the body. These are what you plug the changed image/number/string into so the next iteration starts from where this one ended.

What comes out

Two things you'll actually use. metadata is a DICT describing what the finished loop did - iterations completed, frames collected, and the reason it stopped ("continue_loop was false after N iterations", or "hit the max_iterations limit"). The pack's Loop Metadata node exists to read it; wire it in if you want to log or branch on how a loop ended. The value_1value_8 outputs are the results: each slot's last value, or every value it ever held once accumulate is on.

One detail worth knowing: the safety cap lives on the Open node, not here. max_iterations is a widget on While Loop Open, and Close reads it from the iterator token. If a condition never turns false the loop still dies at that limit - default 100 - which is exactly what you want when you've mis-wired a compare node and it's feeding true forever.

The trap that makes nodes run once and vanish

Only nodes with a path back to Close are part of the loop. ComfyUI re-runs an iteration by re-invoking the nodes wired around the Close; a node in the body whose output goes nowhere - the classic example is a Save Image with nothing after it - runs on the first iteration and never again. If a step must happen every lap, thread its output through a spare value slot on this node so it has a reason to be carried around. This is the single most common "why did my loop only do one pass" failure, and it isn't a bug.

Install

Same pack as always: WAS Node Suite v3. ComfyUI Manager → search "WAS Node Suite v3", or

cd ComfyUI/custom_nodes
git clone https://github.com/WASasquatch/was-node-suite-comfyui

then restart. Requires ComfyUI 0.14.0+ / Python 3.10+, installs no extra packages, and loop nodes need no feature flag. Build the loop body between Open and Close, and remember: something has to decide continue_loop, or you're just counting to 100.

CategoryWAS Suite/Logic/Loop

Inputs (11)

NameTypeDefaultDescription
iteratorWAS_LOOPIdentifies the loop and where it is up to; WAS_LOOP. Wired straight from While Loop Open's iterator output, and nothing else.
continue_loopBOOLEAN,NUMBER,INT,FLOATfalsetrue runs another iteration, false stops; BOOLEAN, or a NUMBER where any non-zero value means true. Read after each iteration, so the body always runs at least once. Wire it from Logic Compare Numbers, Text Compare, or any Logic node.
accumulateBOOLEANfalseCollect every iteration's values; BOOLEAN. On, each value output carries everything that slot received, batched where images, masks or latents batch and a LIST where they do not.
value_1optCOMFY_MATCHTYPE_V3Slot 1's value at the end of this iteration; any type. It goes back to While Loop Open's value_1 for the next one.
value_2optCOMFY_MATCHTYPE_V3Slot {n}'s value at the end of this iteration; any type.
value_3optCOMFY_MATCHTYPE_V3Slot {n}'s value at the end of this iteration; any type.
value_4optCOMFY_MATCHTYPE_V3Slot {n}'s value at the end of this iteration; any type.
value_5optCOMFY_MATCHTYPE_V3Slot {n}'s value at the end of this iteration; any type.
value_6optCOMFY_MATCHTYPE_V3Slot {n}'s value at the end of this iteration; any type.
value_7optCOMFY_MATCHTYPE_V3Slot {n}'s value at the end of this iteration; any type.
value_8optCOMFY_MATCHTYPE_V3Slot {n}'s value at the end of this iteration; any type.

Outputs (9)

NameTypeDescription
metadataDICTWhat the finished loop did, as one value; DICT. Read it with Loop Metadata: iterations completed, frames collected, and why it stopped.
value_1COMFY_MATCHTYPE_V3Slot 1's result; any type. The last value it held, or every value it held once accumulate is on, batched where they batch and a LIST where they do not.
value_2COMFY_MATCHTYPE_V3Slot {n}'s result; any type. Every value it held while accumulate is on, otherwise the last one.
value_3COMFY_MATCHTYPE_V3Slot {n}'s result; any type. Every value it held while accumulate is on, otherwise the last one.
value_4COMFY_MATCHTYPE_V3Slot {n}'s result; any type. Every value it held while accumulate is on, otherwise the last one.
value_5COMFY_MATCHTYPE_V3Slot {n}'s result; any type. Every value it held while accumulate is on, otherwise the last one.
value_6COMFY_MATCHTYPE_V3Slot {n}'s result; any type. Every value it held while accumulate is on, otherwise the last one.
value_7COMFY_MATCHTYPE_V3Slot {n}'s result; any type. Every value it held while accumulate is on, otherwise the last one.
value_8COMFY_MATCHTYPE_V3Slot {n}'s result; any type. Every value it held while accumulate is on, otherwise the last one.