ForEachOpen
Actually loop a chunk of your ComfyUI graph
- initial_value1
- initial_value2
- initial_value3
- initial_value4
- initial_value5
- initial_value6
- initial_value7
- initial_value8
- initial_value9
- initial_value10
- initial_value11
- initial_value12
- initial_value13
- initial_value14
- initial_value15
- initial_value16
- initial_value17
- initial_value18
- initial_value19
- flow_control
- index
- total
- value1
- value2
- value3
- value4
- value5
- value6
- value7
- value8
- value9
- value10
- value11
- value12
- value13
- value14
- value15
- value16
- value17
- value18
- value19
ComfyUI's graph is a one-directional DAG - data flows forward, gets computed once, and that's the run. There's no native for loop, and it trips people up constantly: search around and you'll find the same question asked over and over - "is it possible to for-loop a set of nodes in ComfyUI?" - with the honest answer being no, not natively, you need a purpose-built pair of nodes that fake it by re-triggering execution and carrying state between iterations. ForEachOpen (paired with ForEachClose) is one answer to that; a few other packs have their own version of the same trick, which tells you it's a real, recurring need rather than a one-off feature nobody asked for.
It's part of comfyui-easyapi-nodes, lldacing's utility pack for API-driven ComfyUI work, and this pair is arguably the most structurally different node in the whole thing - everything else in the pack is a straight data-shape converter or a value probe; this one actually changes how a section of your graph executes.
How it works
ForEachOpen marks the start of a loop. You tell it how many times to iterate (total), and it exposes a flow_control output that has to reach a matching ForEachClose node somewhere downstream - that connection is what closes the loop and tells ComfyUI to re-run everything between the two nodes once per iteration instead of once total. Alongside the iteration count and index, it carries up to nineteen arbitrary "value" slots through the loop - accumulators, a running image, a counter you're building up, whatever state needs to survive from one pass to the next, since a plain DAG has no memory of a previous execution to carry forward on its own.
The inputs and outputs that matter
total(INT, default 1, min 1, max 1000, required) - how many iterations to run.initial_value1throughinitial_value19(any type, all optional) - starting values for whatever state you want to track across iterations. You only need to wire up as many as you're actually using.- Output:
flow_control(FLOW_CONTROL) - must connect through to a matching ForEachClose; this is what actually makes the loop loop. - Output:
index(INT) - the current iteration number. - Output:
total(INT) - the total passed back out, handy if a node inside the loop needs to know how many iterations there are in total. - Output:
value1throughvalue19- the current value of each tracked slot for this iteration.
How to install it
Via ComfyUI Manager, searching comfyui-easyapi-nodes. Manual install:
cd ComfyUI/custom_nodes
git clone https://github.com/lldacing/comfyui-easyapi-nodes.git
cd comfyui-easyapi-nodes
pip install -r requirements.txt
Restart ComfyUI afterward. No models involved - this is pure execution-flow logic.
Common issues & troubleshooting
The loop doesn't run, or only runs once. ForEachOpen alone does nothing - flow_control has to actually reach a ForEachClose node for the looping behavior to kick in. If you've dropped ForEachOpen into a graph without its matching close node downstream, you don't have a loop yet.
Values aren't updating between iterations. Only the valueN slots you actually wire an initial_valueN into (and feed back around through ForEachClose) carry state. Anything you're expecting to persist across iterations needs to be routed through one of those numbered slots explicitly - there's no implicit shared state outside them.
People online building their own version of this instead. It's common enough that you'll see users rolling custom loop nodes from scratch rather than hunting for an existing one - a sign this corner of ComfyUI is genuinely underserved, not that ForEachOpen/ForEachClose is unusual or fragile. If this pair doesn't fit your case, that's a reasonable thing to try, but it's worth testing this one first since it's already built, tested, and maintained.
Performance with a high total. A thousand-iteration cap exists for a reason - each iteration re-runs everything between Open and Close, so a large loop around anything GPU-heavy (a full sampling pass, say) adds up fast. Loop around the smallest chunk of the graph that actually needs repeating.
Inputs (20)
| Name | Type | Default | Description |
|---|---|---|---|
| total | INT | 11–1000 | 总循环次数 |
| initial_value1opt | * | — | |
| initial_value2opt | * | — | |
| initial_value3opt | * | — | |
| initial_value4opt | * | — | |
| initial_value5opt | * | — | |
| initial_value6opt | * | — | |
| initial_value7opt | * | — | |
| initial_value8opt | * | — | |
| initial_value9opt | * | — | |
| initial_value10opt | * | — | |
| initial_value11opt | * | — | |
| initial_value12opt | * | — | |
| initial_value13opt | * | — | |
| initial_value14opt | * | — | |
| initial_value15opt | * | — | |
| initial_value16opt | * | — | |
| initial_value17opt | * | — | |
| initial_value18opt | * | — | |
| initial_value19opt | * | — |
Outputs (22)
| Name | Type | Description |
|---|---|---|
| flow_control | FLOW_CONTROL | 开始节点元信息 |
| index | INT | 循环索引值 |
| total | INT | 总循环次数,不宜太大,会影响到消息长度 |
| value1 | * | — |
| value2 | * | — |
| value3 | * | — |
| value4 | * | — |
| value5 | * | — |
| value6 | * | — |
| value7 | * | — |
| value8 | * | — |
| value9 | * | — |
| value10 | * | — |
| value11 | * | — |
| value12 | * | — |
| value13 | * | — |
| value14 | * | — |
| value15 | * | — |
| value16 | * | — |
| value17 | * | — |
| value18 | * | — |
| value19 | * | — |