Now that you understand the logic of the Loop Body and Loop Item, it’s time to move from theory to practice. In Octoparse AI, you implement these concepts using two primary instructions. While the "Start-Body-End" structure remains the same, the "fuel" you choose determines how the repetition triggers.
Loop Through List: Process a Dataset One Item at a Time
A list loop runs the same workflow for each element in a collection. Think of it as “do this for every item.” The instruction to use is Loop through list, which takes a list as its data source and exposes the current item during each iteration.
Why it’s useful: It turns a single action into a scalable batch process. Instead of running your steps manually for every entry, you design once and let the loop handle all elements.
Common use cases include searching multiple product keywords, processing each row in an Excel sheet, or sending notifications to every address in a mailing list.
Quick example (keyword search):
Prepare your list: Create a variable that holds keywords such as ["Apple", "Samsung", "Sony"].
Start the loop: Add Loop through list and select the keyword list as the source.
Build the body: Inside the loop, place the standard “search and collect” steps.
Wire the item: Use the loop’s current item variable as the input to your search box so each iteration substitutes the next keyword automatically.
Outcome: The flow searches and collects results for every keyword in sequence—no manual input required.
Loop by Count: Repeat Actions a Specific Number of Times
A count loop repeats the loop body exactly N times. The instruction Loop by count is ideal when you know how many repetitions you need upfront.
Why it’s useful: It gives you precise control when you’re repeating a predictable sequence. You decide the number; the loop guarantees the exact execution count.
Typical scenarios include scraping a fixed number of paginated result pages or generating a set number of test files.
Quick example (paginate and collect):
Start the loop: Add Loop by count and set the count to the number of pages to capture (for example, 5).
Build the body: Inside, place data collection and pagenation steps.
Counting behavior: The loop counter increments automatically, ensuring the sequence runs five times.
Outcome: The flow gathers data from the first five pages, then exits cleanly.
Choosing the Right Loop: Data vs. Repetition
While both loops automate repetition, they solve different problems:
List loops focus on traversal. You supply a dataset; the loop feeds one element at a time into your flow. Success depends on preparing the list and correctly inserting the loop item variable wherever your steps need it.
Count loops focus on repetition. You supply a number; the loop repeats the same sequence that many times. Success depends on setting the right count and ensuring the loop body is safe to run repeatedly (for example, the “Next page” action should work the same way each time).
A simple rule of thumb: Use a list loop when your targets are known items. Use a count loop when your target is “do this N times.” Both patterns turn repetitive work into reliable, scalable automation with minimal effort.
With these two loop types in your toolkit—and a careful habit of placing all repeatable steps between the loop start and End Loop—you’ll build cleaner, more predictable automations that scale from one item to hundreds with just a few clicks.
Key Takeaways for Success
To ensure your loops run reliably, keep these two implementation rules in mind:
Variable Consistency: In a List Loop, always ensure your actions inside the body reference the Loop Item. If you hardcode a value (like typing "Apple" manually), the loop will just search for "Apple" over and over.
Boundary Discipline: Double-check that all steps intended to repeat are visually nested between the Start and End Loop markers. Any step placed after the End marker will only execute once the entire loop is finished.
Summary
With these two loop types in your toolkit, you can transform single-action workflows into scalable batch processes. Whether you are driving your automation with data or by frequency, the logic of the "Body" and "Item" ensures your bot remains both powerful and predictable.
Looking Ahead: Beyond Basics
While List and Count loops are the workhorses of most automations, advanced workflows may sometimes require more complex logic—such as Loop by Condition (repeating until a specific status is met) or Infinite Loops (for continuous monitoring).
For now, focus on mastering the two core types below. They are the foundation of 90% of all RPA tasks!
