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

- Add a Control Flow › For Each Loop command to your workflow.
- Select the Source Type: Text Lines, File Lines, JSON Array, Numeric Range, or Directory Files.
- Provide source data (raw text, file path, JSON payload, min-max-step values, or folder path).
- Specify the Item Variable (e.g.
item) and optionally an Index Variable (e.g.i). - Insert actions that process each item inside the loop body. Close with End Loop. Save.
Options reference
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
- Insert For Each with File source: C:dataaccounts.txt.
- Item Variable: {account}, Index Variable: {idx}.
- Inside: Type {account} into input field, click Submit, Delay 1500ms.
- 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
