Nodes/Kinburg-Nodes/While (Close)
ComfyUI Node

While (Close)

The Half of the Loop That Actually Decides When to Stop

By Kinburg·Created 3 months ago·Updated 6 days ago· 1
While (Close)
  • flow
  • value_0
  • 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
  • value_0
  • 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
index
condition

While (Open) starts the loop; While (Close) is where the loop decides whether it's done. It takes the condition your body computed, checks it, and either clones the loop body back for another pass or lets the final state flow out. On its own it's half a circuit, but paired with its Open sibling it's how you build a "keep going until it's good enough" loop in a graph engine that technically doesn't allow loops.

What it needs

Three required inputs matter here:

  • flow - the matching While (Open)'s flow output. This is the link that makes the loop a loop.
  • index - the Open node's index output. The Add / link Close button on Open wires both of these for you, so you rarely touch them by hand.
  • condition - a BOOLEAN computed in the loop body. True keeps going, False stops. This is the whole point of the node: the loop runs while the condition is True and stops the moment it flips.

State passes through the auto-growing value_0value_19 wildcard slots, mirrored from Open - the updated values you feed in here are what the next iteration's Open outputs. The outputs of Close are the final state after the loop terminates, so whatever you wire downstream gets the end result, not an intermediate one.

The shape of a real use

The classic: an LLM writes a draft, a judge scores it, you decide it's not good enough and run again - except in ComfyUI there's no if that jumps. Instead you compute the condition in the body (e.g. "is the score below threshold AND have we not hit max_iterations") and feed it to condition. When it finally evaluates False, the last iteration's values are what Close emits, and the loop is done. The max_iterations cap on the Open node is your second line of defense - because a condition that never flips means a loop that never ends, and with no console while semantics there's no Ctrl+C to a running queue.

Install

Part of the Kinburg-Nodes pack - ComfyUI Manager (search "Kinburg-Nodes"), or cd ComfyUI/custom_nodes && git clone https://github.com/Kinburg/Kinburg-Nodes, restart. Pure control flow, no dependencies. One honest note: this is a genuinely thin node - it only makes sense wired to its While (Open). If you look at it sitting alone on the canvas and wonder what it does, that's expected; the pair is the feature.

CategoryKinburg-Nodes/flow/loops

Inputs (23)

NameTypeDefaultDescription
flowKINBURG_LOOP_FLOW
indexINTWire the matching While (Open)'s 'index' output here (the Auto-pair button does this for you).
conditionBOOLEANLoop while this is True. Compute it in the loop body (e.g. a comparison). The loop also stops at the Open node's max_iterations.
value_0opt*
value_1opt*
value_2opt*
value_3opt*
value_4opt*
value_5opt*
value_6opt*
value_7opt*
value_8opt*
value_9opt*
value_10opt*
value_11opt*
value_12opt*
value_13opt*
value_14opt*
value_15opt*
value_16opt*
value_17opt*
value_18opt*
value_19opt*

Outputs (20)

NameTypeDescription
value_0*
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*