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

🐰 For Loop Open - v1 /l

ComfyUI has no loops β€” this is the node that adds them

By MaraScottΒ·Created 3 years agoΒ·Updated 10 months agoΒ· 179
🐰 For Loop Open - v1 /l
  • initial_value1
  • initial_value2
  • initial_value3
  • initial_value4
  • flow_control
  • remaining
  • value1
  • value2
  • value3
  • value4
β—„remaining1β–Ί

Every serious ComfyUI user has hit the wall: you want to run the same KSampler chain three times with slightly different values, and the honest way to do it is to copy-paste the block and rewire everything. Then you need to change one node and you're editing five copies. The MaraScott For Loop set exists to kill that pattern, and For Loop Open is the top half of it.

It pairs with For Loop Close. Open sits at the start of the block you want repeated, Close sits at the end, and everything wired between them runs once per iteration. That's the whole trick - the loop is just a "do this N times" wrapper around whatever subgraph you draw between the two nodes.

How it works

ComfyUI's execution model has no native loop, so this node cheats. On the surface it's simple: you set remaining (an INT, default 1) to the number of iterations, and optionally feed in up to four initial_value1…initial_value4 inputs of any type - these are the loop's "carried" variables, things like a counter or the seed that changes each pass.

Under the hood it uses ComfyUI's graph-expansion machinery (the same GraphBuilder trick that powers a lot of dynamic node packs). When the queue runs, the Open node spawns a While Open node, and the matching Close node rebuilds your loop body on every pass, decrementing the counter and re-running until it hits zero. You never see any of that; you just wire it up.

The inputs and outputs that matter

  • remaining - the iteration count. Set this to how many times the loop body should run. It's also passed out as an output, so you can use the current count inside the body.
  • initial_value1…initial_value4 - optional any-type seeds. Anything you want to change per pass goes in here.
  • Outputs: flow_control (wire this straight into For Loop Close's flow_control input), remaining (INT), and value1…value4, which carry your carried values through the body and into the Close node.

The loop's own little support nodes live in the same menu section: For Loop IntMathOperation (add, subtract, multiply, divide, modulo, power on INTs - handy for a counter) and For Loop ToBoolNode (any value to a BOOLEAN, with an invert switch), which is what you'd use for a while-style condition.

Installing it

This node ships inside the MaraScott pack, so install is identical to any of its siblings. Easiest: ComfyUI Manager β†’ Custom Nodes Manager β†’ search "MaraScott" β†’ Install, then restart ComfyUI. Or from ComfyUI/custom_nodes:

git clone https://github.com/MaraScott/ComfyUI_MaraScott_Nodes

Then restart. Fair warning: this pack's requirements.txt pins transformers==4.37.2 and drags in opencv-python, numba, blend_modes and a couple of LLM libs - it's a chunky install for what looks like a handful of utility nodes, and the pinned old transformers can fight newer packs. If pip throws a conflict, that pin is the usual culprit.

Common issues

Loops rely on ComfyUI's dynamic graph expansion, which is a recent-core feature. If the loop does nothing, or errors with a GraphBuilder-looking traceback, update ComfyUI first. The other classic gotcha: keep your carried values inside the loop. Value wires that escape the Open→Close boundary defeat the whole point and behave unpredictably - treat the space between Open and Close as a closed circuit. Keep the loop body small and it's genuinely lovely; try to loop half a workflow and you'll remember why copy-paste died for a reason.

Category🐰 MaraScott/Loop/Flow

Inputs (5)

NameTypeDefaultDescription
remainingINT10–100000β€”
initial_value1opt*β€”
initial_value2opt*β€”
initial_value3opt*β€”
initial_value4opt*β€”

Outputs (6)

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