Nodes/comfy-ovum/Foreach List Begin Ovum
ComfyUI Node

Foreach List Begin Ovum

Loop over a list in ComfyUI without illegal graph cycles

By sfinktah·Created about a year ago·Updated 10 months ago· 7
Foreach List Begin Ovum
  • py_list
  • init_accum
  • flow_control
  • remaining_list
  • accum
  • value
  • index
  • array

ComfyUI's graph model doesn't allow loops. A wire from a node back to an earlier node is an "illegal cycle," and the executor refuses to run it. That's a real problem the moment you want to process every item in a list - feed 20 prompts through a sampler, generate a variant per LoRA, apply the same upscale to each of a dozen images - because "repeat this subgraph N times" is exactly the thing acyclic graphs can't express natively.

This node is half the workaround. ForeachListBeginOvum is the "for" statement, and its partner ForeachListEndOvum (same pack, same ovum/loop category) is the closing brace. Between them you build a loop body that runs once per item, and ComfyUI executes it as a recursive expansion rather than a cycle. The author's own comment in the source: he stole the design from easyUse to learn how it worked. It's a proven pattern, not a new invention.

The inputs that matter

  • py_list (ITEM_LIST) - the list you're iterating over. Each item comes out one at a time.
  • init_accum (*) - the seed for the accumulator. This is the clever bit: the loop body takes the current item and the running accum, produces a new accum, and hands it back. Leave init_accum unconnected and an empty list is used as the seed.

Outputs worth knowing:

  • flow_control - pass this to ForeachListEndOvum; it's the thing that tells the loop where it ends.
  • value (*) - the current item.
  • accum (*) - the running result so far.
  • index (INT) - which iteration you're on, starting at 0.
  • remaining_list and array - the leftovers and an immutable copy of the input, handy for debug or for loop conditions.

The pattern

Wire your list in, wire the value and accum outputs into whatever processing you want per item (prompt tweak, sampler, batch op), feed the result back into ForeachListEndOvum, and grab the final accumulated list from the End node. The seed accumulates per run, so you can build up a results list, a concatenated image batch, or anything else that's a natural "fold" over the items.

One honest caveat: this is fiddly to get right the first time. The loop-body subgraph has specific expectations about what goes where, and ComfyUI evaluates it recursively, so a wiring mistake shows up as a confusing execution error rather than a friendly hint. Start with a three-item list and a trivial body (append index to a list) before you build the real pipeline.

Installing it

Part of comfy-ovum:

cd ComfyUI/custom_nodes
git clone https://github.com/sfinktah/comfy-ovum

Or ComfyUI Manager → search "comfy-ovum". Restart after installing. The loop nodes are pure Python - no models, no extra deps.

Gotchas

Loops here are unrolled, not runtime iterations, so don't expect "infinite" anything - the list size is the run count, and a very long list means a very long unrolled graph (and slow prompt builds). Keep the accumulator logic pure and stateless where you can, since each pass is re-evaluated. And remember there are two ends of the fork: if your End node and Begin node disagree about types, you'll get an error about mismatched sockets that reads like Greek until you notice the tiny accum type mismatch.

Categoryovum/loop

Inputs (2)

NameTypeDefaultDescription
py_listITEM_LISTA list containing items to be processed iteratively.
init_accumopt*Initial value for the accumulator (accum) before processing items.

Outputs (6)

NameTypeDescription
flow_controlFOREACH_LIST_CONTROLPass ForeachListEndOvum as is to indicate the end of the iteration.
remaining_listITEM_LISTOutput the ITEM_LIST containing the remaining items during the iteration, passing ForeachListEndOvum as is to indicate the end of the iteration.
accum*Output the accumulated results during the iteration.
value*Output the current item during the iteration.
indexINTThe index of the current item (starting at 0).
arrayITEM_LISTAn immutable copy of the input list.