Skip to main content

What is the Loop Block?

The Loop block lets you repeat a set of workflow steps for each item in a list. Think of it like a “for each” loop in programming - it takes a list of items and runs the same workflow steps once per item. Common use cases:
  • Process multiple keywords for SEO analysis
  • Analyze a list of competitor URLs
  • Generate content for multiple topics
  • Send data to multiple destinations
  • Process rows from a spreadsheet

How Does the Loop Block Work?

The Loop block works in three stages:

1. Setup Phase

You provide a list of items (array) to loop through. This can be:
  • Output from a previous step
  • Hardcoded array
  • Data from Google Sheets
  • Search results

2. Iteration Phase

For each item in the list:
  • The loop creates special variables: element and element_index
  • All blocks inside the loop execute once
  • Results are collected

3. Completion Phase

After all iterations:
  • Loop output contains an array of results
  • Each position in the array matches an item from your original list
Example:
Input list: ["keyword1", "keyword2", "keyword3"]
Loop runs 3 times (once per keyword)
Output: [result1, result2, result3]

What is a List?

A list (also called an array) is a collection of items in a specific order. Examples of lists: Simple list of strings:
["crm software", "marketing automation", "sales tools"]
List of numbers:
[100, 250, 500, 1000]
List of objects:
[
  {"keyword": "crm", "volume": 74000},
  {"keyword": "marketing", "volume": 33100}
]
List of URLs:
[
  "https://example.com/blog/post-1",
  "https://example.com/blog/post-2"
]

How Do I Create a List?

You can create lists in several ways:

Method 1: From LLM Block Output

LLM blocks can generate lists directly. Setup:
  1. Add LLM block before your loop
  2. Set output format to JSON
  3. In your prompt, ask for a list
Example prompt:
Generate a list of 5 blog post topics about CRM software.
Return as JSON array of strings.
LLM Output:
[
  "How to Choose the Right CRM",
  "CRM Implementation Best Practices",
  "CRM vs Spreadsheets",
  "Mobile CRM Features",
  "CRM Integration Guide"
]
Loop configuration:
{{step_2.output}}

Method 2: From Code Block (Python)

Use Python to create or transform lists. Example 1: Create a simple list
    keywords = ["crm software","marketing automation","sales tools"]
    return keywords
Loop configuration:
{{step_3.output}}

Method 3: From Google Search Block

Google Search returns structured search results with organic listings. The Google Search block returns an object containing organic results, each with title, link, snippet, and other metadata. Google Search output structure:
{
  "organic": [
    {
      "title": "Best Email Marketing Tools 2025",
      "link": "https://example.com/email-tools",
      "snippet": "Compare the top email marketing platforms...",
      "position": 1
    },
    {
      "title": "Email Marketing Guide",
      "link": "https://example.com/guide",
      "snippet": "Complete guide to email campaigns...",
      "position": 2
    }
  ]
}
Then configure your loop:
step_1.output.organic
Inside the loop, access each result’s properties:
Title: {{step_3.element.title}}
URL: {{step_3.element.link}}
Snippet: {{step_3.element.snippet}}
Example workflow:
  1. Google Search block - Search “email marketing tools”
  2. Loop through results
    • Web Scrape block - Scrape each URL
    • LLM block - Analyze content and extract key features
  3. Text block - Compile analysis results
This lets you automatically analyze each search result in depth.

Method 4: Hardcoded List

Type a list directly in the loop configuration. Simple list:
["keyword 1", "keyword 2", "keyword 3"]
List of objects:
[
  {"name": "Competitor A", "url": "https://competitora.com"},
  {"name": "Competitor B", "url": "https://competitorb.com"}
]

What is the Element and Element Index?

When the loop runs, it creates two special variables for each iteration:

Element

element is the current item from your list. If your list is:
["crm", "marketing", "sales"]
Then during each iteration:
  • Iteration 1: element = “crm”
  • Iteration 2: element = “marketing”
  • Iteration 3: element = “sales”

Element Index

element_index is the position number (starting from 0). For the same list:
  • Iteration 1: element_index = 0
  • Iteration 2: element_index = 1
  • Iteration 3: element_index = 2
Why is it useful?
  • Know which iteration you’re on
  • Use for conditional logic
  • Reference back to original list position

How Do I Reference the Element?

Use the element and element_index variables inside your loop blocks.

Syntax for Referencing

In most blocks, use:
{{step_X.element}}
Where X is your loop’s step number.

Example 1: Simple String List

Loop items:
["crm software", "marketing tools", "sales automation"]
Inside loop - LLM block prompt:
Analyze this keyword: {{step_5.element}}

Generate a content brief including:
- Search intent
- Target audience
- Key topics to cover
Iteration 1: Analyzes “crm software” Iteration 2: Analyzes “marketing tools” Iteration 3: Analyzes “sales automation”

Example 2: List of Objects

Loop items:
[
  {"keyword": "crm", "volume": 74000},
  {"keyword": "marketing", "volume": 33100}
]
Access object properties:
Keyword: {{step_5.element.keyword}}
Volume: {{step_5.element.volume}}
Inside loop - LLM block prompt:
Create a blog post outline for the keyword "{{step_5.element.keyword}}"
which has {{step_5.element.volume}} monthly searches.

Example 3: Using Element Index

Show progress or numbering:
Processing item {{step_5.element_index}} of the list.
Current keyword: {{step_5.element}}
Conditional logic based on index:
index = input_data['step_5']['element_index']
keyword = input_data['step_5']['element']

# Different behavior for first item
if index == 0:
    return f"Starting with: {keyword}"
else:
return f"Also processing: {keyword}"

What Does the Output Look Like?

The loop’s output is an array where each position contains the result from that iteration’s final block.

Example 1: Simple Output

Loop items:
["keyword1", "keyword2", "keyword3"]
Blocks inside loop:
  1. Keyword Overview (gets metrics)
Loop output (step_5.output):
[
  {"Keyword": "keyword1", "Search Volume": "10000", ...},
  {"Keyword": "keyword2", "Search Volume": "5000", ...},
  {"Keyword": "keyword3", "Search Volume": "8000", ...}
]

Example 2: Nested Loop Output

Loop items:
["topic1", "topic2"]
Blocks inside loop:
  1. LLM block (generates outline)
Loop output (step_5.output):
[
  "# Outline for topic1\n## Introduction\n## Main Points",
  "# Outline for topic2\n## Introduction\n## Main Points"
]

Example 3: Complex Object Output

Loop through keywords, get metrics and generate content: Loop output (step_5.output):
[
  {
    "keyword": "crm software",
    "metrics": {"volume": 74000, "difficulty": 76},
    "content_brief": "Comprehensive guide to CRM..."
  },
  {
    "keyword": "marketing automation",
    "metrics": {"volume": 33100, "difficulty": 68},
    "content_brief": "Marketing automation overview..."
  }
]

Best Practices

Loop Configuration

  • Start small: Test with 2-3 items before scaling to 100+
  • Check your list: Use Code block to verify list format before loop
  • Handle errors: Set error behavior based on criticality

Referencing Elements

  • Use descriptive names: If you nest loops, keep track of step numbers
  • Test references: Add a text block inside loop to verify {{step_X.element}}
  • Object properties: Use dot notation for objects: {{step_5.element.property}}

Performance

  • Limit iterations: 100+ iterations can be slow, consider batching
  • Async where possible: Semrush blocks run independently
  • Use filters: Filter your list before looping, not during

Output Handling

  • Format for next step: Transform output immediately after loop
  • Debug output: Add a simple text block after loop to inspect results

Common Patterns

Pattern 1: Keyword Research Pipeline

1. Related Keywords block → returns array
2. Loop through keywords
   - Keyword Overview (get metrics)
   - LLM (create content brief)
3. Code block (format results)
4. Google Sheets (save)

Pattern 2: Competitor Analysis

1. Code block → create list of competitor URLs
2. Loop through URLs
   - Domain Overview
   - Backlink Overview
   - Domain Organic Keywords
3. Code block (compare metrics)
4. LLM (generate analysis report)

Pattern 3: Content Generation at Scale

1. Google Sheets → read list of topics
2. Loop through topics
   - LLM (generate outline)
   - LLM (write introduction)
   - LLM (write conclusion)
3. Code block (combine sections)
4. Google Sheets (write back)

Troubleshooting

”Items is not a list” Error

Problem: Your items configuration doesn’t return an array. Solution: Check that your code/reference returns [...] format:
// Wrong - returns object
{{step_1.output}}

// Right - returns array
{{step_1.output.results}}

Element Reference Not Working

Problem: {{step_X.element}} shows blank. Solution: Make sure X matches your loop’s step number. Check workflow step numbers.

Loop Never Finishes

Problem: Loop seems to hang. Solution:
  • Check for very large lists (1000+ items)
  • Verify blocks inside loop don’t have infinite waits
  • Check error handling settings

What’s Next

Now that you understand the Loop block: