Loop

Repeat operations a specified number of times

Overview

The Loop utility repeats a section of your flow a specified number of times. Unlike Array Iterator which processes existing data, Loop generates iterations from scratch based on a count you provide.

This is useful for batch operations, retries, generating test data, or any scenario where you need to repeat an action multiple times.

Configuration

Iterations

The number of times to repeat the loop. Can be a static number or dynamic value.

10Static: run 10 times{{#1.data.retryCount}}Dynamic: based on previous node

Start Index

The starting value for the iteration index. Default is 0.

0

Output

For each iteration, the loop outputs:

Output fields:

  • index - Current iteration number (starts from Start Index)
  • iteration - 1-based iteration count
  • total - Total number of iterations
  • isFirst - True if this is the first iteration
  • isLast - True if this is the last iteration

Examples

Example 1: Generate Test Data

Create 50 test records for development:

Iterations:50
Start Index:1

Use {{loop.index}} to create unique IDs for each record.

Example 2: Retry Logic

Attempt an operation up to 3 times:

[Loop: 3] ──▶ [HTTP Request] ──▶ [IF: Success] ──▶ True: [Break Iteration]
     │                                  │
     ▼                                  ▼
  Attempt 1                      False: Continue to next attempt
  Attempt 2
  Attempt 3

Combine with Break Iteration to exit early when successful.

Example 3: Pagination

Fetch multiple pages of data from an API:

Iterations:10
Start Index:1

In HTTP Request: ?page={{loop.index}}
Fetches pages 1 through 10.

Example 4: Batch Processing

Process data in batches of 100:

Total items: 500
Batch size: 100
Iterations needed: 5

[Loop: 5] ──▶ [Code: Get Batch] ──▶ [Process Batch]
    │
    ▼
  Batch 1: items 0-99
  Batch 2: items 100-199
  Batch 3: items 200-299
  ...

Tips

Tip: Use Break Iteration inside the loop to exit early based on a condition.

Tip: Set Start Index to 1 instead of 0 when working with 1-based systems like page numbers.

Warning: Be careful with dynamic iteration counts. Very large numbers can cause long execution times or resource issues.

Note: Loop creates new bundles, it doesn't carry forward data from previous nodes. Use Set Variable or input mappings to pass data into the loop.

Loop Utility - Flows Guide - Serenities