DocsFlowFor Each Loop

Iterate data collections with For Each Loop in RunMacro

Desktop ModeBrowser ModeRunMacro RunnerRunMacro 3.5+

For Each Loop iterates over collections (text lines, files, JSON arrays, ranges, folders) and binds each element to a variable.

Dialog & quick setup

RunMacro For Each Loop command configuration dialog showing parameter fields
Configuration dialog and parameter fields for the For Each Loop command in RunMacro.
  1. Add a Control Flow › For Each Loop command to your workflow.
  2. Select the Source Type: Text Lines, File Lines, JSON Array, Numeric Range, or Directory Files.
  3. Provide source data (raw text, file path, JSON payload, min-max-step values, or folder path).
  4. Specify the Item Variable (e.g. item) and optionally an Index Variable (e.g. i).
  5. Insert actions that process each item inside the loop body. Close with End Loop. Save.

Options reference

Source Type

Collection source: text lines, file lines, json array, numeric range, or folder files.

Item Variable

Variable name receiving the value of the active item on each iteration.

Index Variable

Optional variable receiving the 0-based iteration index.

File Pattern / Glob

Wildcard filter when scanning directory files (e.g. *.xlsx, *.png, *.txt).

Numeric Range (Min, Max, Step)

Start, stop, and step increment values when iterating integer sequences.

Modes & when to use

Desktop Mode
Browser Mode
RunMacro Runner

Best for

  • Reading each line of a user or phone number list file to execute batch automations.
  • Looping through images or documents in a local folder to batch upload or rename them.
  • Iterating items returned from a REST API JSON array or database query.
  • Running numbered iterations across a numeric range (e.g. page numbers 1 through 20).

Use an alternative when

  • Repeating an identical action unrelated to any data set (use Loop instead).
  • Looping on dynamic asynchronous state changes (use While instead).
Before you run
  • Source file or JSON collection exists and is accessible.
  • Target variable names are configured clearly for child commands to consume.

Example workflow

Example: Iterate lines from a file and submit into a web form

  1. Insert For Each with File source: C:dataaccounts.txt.
  2. Item Variable: {account}, Index Variable: {idx}.
  3. Inside: Type {account} into input field, click Submit, Delay 1500ms.
  4. Close with End Loop. Execution completes when all lines have been processed.
Expected result: Each collection element is bound to the target variable and processed by child commands until the collection is exhausted.

Tips & limitations

Combine with Break Loop inside For Each to exit immediately once a target record is found.
When iterating large files, For Each streams content efficiently to maintain minimal RAM usage across tens of thousands of lines.
  • If the source file is deleted or locked mid-execution, iteration fails with an I/O error.
  • Source JSON strings must be strictly valid JSON; syntax errors prevent the loop from initializing.

Applies to RunMacro 3.5+ · Desktop Mode & Browser Mode & RunMacro Runner · Windows 10/11

RunMacro robot

Robots do the work. Your time is yours.

Create a robot in minutes, no coding needed. Reliable execution, remote management, transparent costs — and you always stay in control.