Nodes/comfyui-huyl2-nodes/Simple While Open
ComfyUI Node

Simple While Open

A real loop primitive, hiding in an otherwise very personal node pack

By huyl3-cpu·Created 9 months ago·Updated 4 months ago· 1
Simple While Open
  • initial_value0
  • initial_value1
  • initial_value2
  • initial_value3
  • initial_value4
  • flow
  • value0
  • value1
  • value2
  • value3
  • value4
conditiontrue

ComfyUI's default execution model is straight-line: every node runs once, the graph is a DAG, and there's no native "repeat this until X" construct. A small handful of packs work around that with a special socket type - FLOW_CONTROL - that the executor recognizes as a signal to re-run the subgraph between a matching pair of nodes. SimpleWhileOpen and its partner SimpleWhileClose are huyl3-cpu's version of that pattern: a lightweight while-loop for ComfyUI, tucked into an otherwise very idiosyncratic personal node pack.

If you've never needed a loop in ComfyUI, you probably won't need this either - most workflows are one straight pass through the graph, and for-style repetition over a list (a batch of images, a list of file paths) is usually handled by ComfyUI's own list/batch semantics rather than an explicit loop. Reach for this when you genuinely need conditional repetition: process something, check a stop condition that depends on the result, and keep going until it's satisfied - a shape a plain list can't express because you don't know the iteration count up front.

The inputs and outputs that matter

  • condition - a BOOLEAN, checked to decide whether to enter the loop at all. Default true.
  • initial_value0 through initial_value4 - five optional slots of any type (*). These seed the values you want to carry around the loop: a counter, an accumulator, a running list, whatever your loop body needs on its first pass.

Output: flow - the FLOW_CONTROL handle. Route this into the first node of whatever you want repeated. The five value0value4 outputs pass the initial values straight through alongside it, so the first pass of your loop body has something to work with.

The actual repetition happens on the other end, in SimpleWhileClose: it's the one that re-checks the condition each pass and either loops back or lets the final values continue downstream.

Installing it

ComfyUI Manager: search comfyui-huyl2-nodes, install, restart. By hand:

cd ComfyUI/custom_nodes
git clone https://github.com/huyl3-cpu/comfyui-sortlist

restart. The pack's README doesn't document this node (it covers exactly one, unrelated, node), so there's no author-written guide to loop usage here - this is a case where reading the node's own source, or just experimenting on a small test graph, is the fastest way to get comfortable with it.

Common issues & troubleshooting

The loop shape (Open sets up, Close checks and either repeats or releases) is a pattern that shows up in a few other ComfyUI packs under different names, so if you've used a "while loop" or "for loop" pair from another pack before, the mental model transfers - but the exact wiring conventions (which slot means what) are this pack's own, so don't assume field-for-field compatibility with a different pack's loop nodes.

The most common way this bites people: mismatched slot usage between Open and Close. Nothing in the schema enforces that initial_value0 on Open corresponds to the same logical variable as initial_value0 on Close - if you wire them inconsistently, you'll get None or unexpected values silently rather than an error. Keep a mental (or literal, in a Note node) map of what each numbered slot represents.

And because this is a genuine loop with no built-in iteration cap, an always-true condition means an infinite loop - ComfyUI will just hang. There's no separate max-iterations safety valve here the way some other packs' loop nodes provide, so make sure your condition logic inside the loop body actually has a path to false.

Categorycomfyui-sortlist/flow

Inputs (6)

NameTypeDefaultDescription
conditionBOOLEANtrue
initial_value0opt*
initial_value1opt*
initial_value2opt*
initial_value3opt*
initial_value4opt*

Outputs (6)

NameTypeDescription
flowFLOW_CONTROL
value0*
value1*
value2*
value3*
value4*