For Each Open
Iterate over up to 50 of anything, typed automatically
- initial_value
- value0
- value1
- value2
- value3
- value4
- value5
- value6
- value7
- value8
- value9
- value10
- value11
- value12
- value13
- value14
- value15
- value16
- value17
- value18
- value19
- value20
- value21
- value22
- value23
- value24
- value25
- value26
- value27
- value28
- value29
- value30
- value31
- value32
- value33
- value34
- value35
- value36
- value37
- value38
- value39
- value40
- value41
- value42
- value43
- value44
- value45
- value46
- value47
- value48
- value49
- flow
- index
- item
- value
A counting loop is great, but half the time what you actually want is: "run my pipeline once for each of these things." You have three prompts, five images, a folder of style references - you want one node to hand each one to your graph in turn. That's For Each Open, the loop that iterates over values instead of integers, from the ComfyUI-ForLoops pack (JkNodes category).
It's the node people describe as "a switch-any and a loop in one." Connect one input and it adopts that input's type; connect a second, a third, up to fifty, and it runs your loop body once per connected value, spitting out the current one as item each pass.
How it works
Two halves. On the frontend, the bundled JavaScript does the ergonomics: as you connect inputs it adds a fresh empty slot, removes ones you unplug, re-numbers the surviving slots contiguously, and propagates the type of the first connected input to every slot and to the item/value outputs. Connect a string and all the sockets turn into string sockets; connect a checkpoint loader's output and they all turn into that. That's the "typed switch-any" behavior - it's genuinely handy and it's rare to see done this cleanly.
On the backend, the node gathers whatever value0 … value49 are actually connected and hands the loop machinery a count and an index. index is the 0-based position, item is values[index] for this iteration. Same graph-expansion execution as the plain For loop - everything downstream of Open, up to For Each Close, runs once per item, all inside one Queue Prompt.
The inputs and outputs that matter
value0 … value49(optional, dynamic) - connect anything, any type. Slots appear as you go, so you never count them; there's a hard ceiling of 50.initial_value(optional) - an accumulator threaded through the loop and returned when it ends. For plain iteration, ignore it.item(output) - the current element for this iteration. This is your main driver wire.index(output) - current 0-based position.flow(output) - wire this to For Each Close → flow. It's typedJK_FOREACH_FLOW, so it deliberately won't plug into a plain For Close.value(output) - the accumulator, if you're threading one.
There's also a hidden _i counter input the JavaScript removes from view - loop state, nothing you set.
Installing it
One install gets all four loop nodes:
cd ComfyUI/custom_nodes
git clone https://github.com/jeankassio/ComfyUI-ForLoops
Restart ComfyUI. Or use ComfyUI Manager and search "ComfyUI-ForLoops". No dependencies, no models - just Python plus a small JS file.
Wiring your first For Each
For Each Open ──flow──────────► For Each Close
└─item─► [ prompt → generate → Save Image ]
Connect three strings into the Open node's slots and your generator runs three times, once per string. If the body result feeds back into the Close node's value, you can even accumulate - the README's example workflow concatenates three strings into one across iterations.
Gotchas
- All connected inputs share one type. The node adopts the type of the first connection and forces every slot to it. Don't mix a string and a latent in the same loop - it won't let you, and that's correct behavior, not a bug.
- Nothing connected = no iterations. With zero inputs the loop just doesn't run, so a dead For Each Close output usually means you forgot to plug the slots.
- The 50-input ceiling is real, and each connected slot means a full run of your loop body, so fifty heavy generations is fifty times the runtime - plan accordingly.
- Young pack. First commit June 2026, one author, announced on r/comfyui with zero replies. The engine underneath is the official graph-expansion pattern, but there's no community lore yet if something goes sideways.
Inputs (52)
| Name | Type | Default | Description |
|---|---|---|---|
| initial_valueopt | * | Optional accumulator threaded through the loop. | |
| _iopt | INT | 0 | — |
| value0opt | * | — | |
| value1opt | * | — | |
| value2opt | * | — | |
| value3opt | * | — | |
| value4opt | * | — | |
| value5opt | * | — | |
| value6opt | * | — | |
| value7opt | * | — | |
| value8opt | * | — | |
| value9opt | * | — | |
| value10opt | * | — | |
| value11opt | * | — | |
| value12opt | * | — | |
| value13opt | * | — | |
| value14opt | * | — | |
| value15opt | * | — | |
| value16opt | * | — | |
| value17opt | * | — | |
| value18opt | * | — | |
| value19opt | * | — | |
| value20opt | * | — | |
| value21opt | * | — | |
| value22opt | * | — | |
| value23opt | * | — | |
| value24opt | * | — | |
| value25opt | * | — | |
| value26opt | * | — | |
| value27opt | * | — | |
| value28opt | * | — | |
| value29opt | * | — | |
| value30opt | * | — | |
| value31opt | * | — | |
| value32opt | * | — | |
| value33opt | * | — | |
| value34opt | * | — | |
| value35opt | * | — | |
| value36opt | * | — | |
| value37opt | * | — | |
| value38opt | * | — | |
| value39opt | * | — | |
| value40opt | * | — | |
| value41opt | * | — | |
| value42opt | * | — | |
| value43opt | * | — | |
| value44opt | * | — | |
| value45opt | * | — | |
| value46opt | * | — | |
| value47opt | * | — | |
| value48opt | * | — | |
| value49opt | * | — |
Outputs (4)
| Name | Type | Description |
|---|---|---|
| flow | JK_FOREACH_FLOW | — |
| index | INT | — |
| item | * | — |
| value | * | — |