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:
elementandelement_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
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: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:- Add LLM block before your loop
- Set output format to JSON
- In your prompt, ask for a list
Method 2: From Code Block (Python)
Use Python to create or transform lists. Example 1: Create a simple listMethod 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:- Google Search block - Search “email marketing tools”
- Loop through results
- Web Scrape block - Scrape each URL
- LLM block - Analyze content and extract key features
- Text block - Compile analysis results
Method 4: Hardcoded List
Type a list directly in the loop configuration. Simple list: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:
- 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
- Know which iteration you’re on
- Use for conditional logic
- Reference back to original list position
How Do I Reference the Element?
Use theelement and element_index variables inside your loop blocks.
Syntax for Referencing
In most blocks, use:Example 1: Simple String List
Loop items:Example 2: List of Objects
Loop items:Example 3: Using Element Index
Show progress or numbering: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:- Keyword Overview (gets metrics)
step_5.output):
Example 2: Nested Loop Output
Loop items:- LLM block (generates outline)
step_5.output):
Example 3: Complex Object Output
Loop through keywords, get metrics and generate content: Loop output (step_5.output):
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
Pattern 2: Competitor Analysis
Pattern 3: Content Generation at Scale
Troubleshooting
”Items is not a list” Error
Problem: Your items configuration doesn’t return an array. Solution: Check that your code/reference returns[...] format:
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:- Process multiple items with Code Block
- Store results in Google Sheets
- Analyze keywords with Semrush blocks
- Generate content with LLM Block
- Learn about variables in Variable Referencing