LoopFlow
Tutorial Workshop Keywords ๐ŸŽฎ LoopFlow Lab
Keywords / for each

for each

Run a template once per item. Compose

Syntax

for each <var> in "<file>":
  run "<template.loop>"

What it does

Dynamic fan-out inside a flow: read a plan file and run a single template loop once per item โ€” each item's text becomes that run's context (what to build). The source is a .yaml file (a list, or a single-key list like items:) or a .md file (which splits on each ## section). If an item's own checklist fails, the flow pauses and asks: continue with the next item, or stop?

Reach for for each when you have a backlog of same-shaped work โ€” a dozen endpoints to scaffold, a list of stories to deliver, a set of files to migrate โ€” where the steps are identical but the subject differs each time. Instead of writing one stage per item by hand, you write the template once and let a planning step discover the list at run time. That is the key difference from a fixed pipeline: the number and content of items are not known when you author the flow; they are read from the plan file when the flow runs, so the same flow adapts as the backlog grows or shrinks. It is method-neutral โ€” the plan file can be any checklist, not only a BMAD backlog โ€” and the per-item pause on failure keeps a single bad item from silently poisoning the whole batch.

Examples

flow "deliver":
  for each item in "plan.yaml":
    run "item-template.loop"
examples/foreach/deliver.loop
# plan.yaml โ€” .yaml list (or .md: each "## " section is one item)
items:
  - title: Parse the uploaded CSV into rows
  - title: Validate rows against the schema
the source file

How it runs

๐Ÿ“„ plan.yamlthe work list item 1 item 2 item 3 โ€ฆ โ–ถ item-template.loop โ–ถ item-template.loop โ–ถ item-template.loop same template, once per item โ€” if one fails, it pauses and asks: continue or stop?
for each is dynamic fan-out: a planning step discovers the items, then the same template runs once per item.

Common mistakes

Related