Break
Use the Break task inside a ForEach loop to stop the execution.
When the Break task runs:
- The rest of the current iteration is skipped.
- No further iterations run.
- The job continues with the first task after the ForEach End of the loop.
Note:
- A Break task can only be placed inside a ForEach loop. A job with a Break that is not inside a loop is not valid and does not run.
- A Break can be placed inside an If block that is inside a ForEach; it still stops the ForEach loop.
- When loops are nested, Break stops the innermost (nearest) loop only; outer loops continue.
Example
The following job exports data for each region but stops the loop when more than 10 errors have accumulated:
Open Analysis from Library
ForEach (Data Table: "Regions", Column: "Region")
If
result = AutomationContext.Application.Document.Properties["ErrorCount"] > 10
Break
End If
Export Data
ForEach End