Nodes/🐰 MaraScott Nodes/🐰 For Loop Close - v1 /l
ComfyUI Node

🐰 For Loop Close - v1 /l

The other half of the loop β€” where the iteration actually happens

By MaraScottΒ·Created 3 years agoΒ·Updated 10 months agoΒ· 179
🐰 For Loop Close - v1 /l
  • flow_control
  • initial_value1
  • initial_value2
  • initial_value3
  • initial_value4
  • value1
  • value2
  • value3
  • value4

For Loop Close is the bottom half of the MaraScott loop pair, and it's where the magic - and the occasional headache - actually lives. The Open node just declares "we're looping N times" and hands you a flow_control wire. Close is the node that receives that wire at the far end of your loop body and decides, on every pass, whether to run the body again or stop and hand back the results.

You don't use this node alone. It's meaningless without a For Loop Open upstream. Together they wrap the subgraph between them, and Close is what makes the repetition finite.

How it works

Wire flow_control from Open into Close's flow_control input, route your carried values (initial_value1…initial_value4, any type) through the loop body, and they come out as value1…value4 on Close.

Internally, Close counts down. It takes the Open node's remaining counter and builds a While Close node plus an IntMathOperation doing remaining - 1, feeding a ToBoolNode to produce the "keep going?" condition. If the condition is still true, it reconstructs the entire loop body once more using ComfyUI's dynamic graph expansion (GraphBuilder), re-wires your carried values into the new copy, and repeats. When the counter hits zero it stops and emits the final values. From your side it looks like the node just "loops"; underneath it's actually cloning your graph per pass.

The inputs and outputs that matter

  • flow_control (required) - connect the Open node's flow_control output here. This is the only hard requirement, and it's what lets Close locate the start of the loop.
  • initial_value1…initial_value4 (optional, * type) - the per-pass values you want to propagate.
  • Outputs: value1…value4 - the final values after the last iteration. Wire these to whatever consumes the loop's result.

One thing to know: the Close node is the bottom of the loop, so nodes after it see only its outputs. If your loop accumulates something (say, a concatenated list of captions), the accumulation has to happen inside the body and come back through one of the value wires - there's no side-channel out.

Installing it

Same pack as everything else: ComfyUI Manager β†’ search "MaraScott" β†’ Install β†’ restart. Or:

cd ComfyUI/custom_nodes
git clone https://github.com/MaraScott/ComfyUI_MaraScott_Nodes

Then restart ComfyUI. The pack pulls in opencv-python, numba, blend_modes and pins transformers==4.37.2 - heavy for a loop node, and the pin is the first suspect if pip starts complaining.

Common issues

Loops depend on modern ComfyUI's graph expansion. If Close errors out or the loop runs zero times, update ComfyUI before touching anything else. The classic failure mode is an infinite-ish loop from a condition that never flips - keep remaining modest while you're testing, because a runaway expansion will visibly grind the queue. And remember the whole point: keep the loop body small and self-contained. Close enforces nothing about that, so a 40-node body will still "work" - it'll just take forever and be miserable to debug.

Category🐰 MaraScott/Loop/Flow

Inputs (5)

NameTypeDefaultDescription
flow_controlFLOW_CONTROLβ€”
initial_value1opt*β€”
initial_value2opt*β€”
initial_value3opt*β€”
initial_value4opt*β€”

Outputs (4)

NameTypeDescription
value1*β€”
value2*β€”
value3*β€”
value4*β€”