How to loop your automation
Learning how to loop is one of the critical skills to learn when using Axiom.ai. Looping is a method for repeating steps. Most loops will also involve iterating through rows of data. For example, looping through URLs to extract data from a webpage or looping through rows of data to input into a web form.
There are three steps you can use to create loops with, the primary method is using the ‘Loop through data’ step, and the jump, conditional jump steps can also be used to perform loops. It's also worth noting that logic can be used inside your loops.
# Learning to loop using the "Loop through data" step
The primary method for performing loops is the "Loop through data" step. For each row of data passed into the step it will perform a loop, repeating the steps nested inside the loop step. First, you will need to add the loop step, and select data to loop through.
# How to add a "Loop through data" step
There are two ways to create loops: either use the Step finder or add a "loop through data" step using are "Move" toolbar.
How to use the Step finder to add a loop
- Insert the step using the step finder, search for "loop" and add the step.
- Add steps as sub-steps if you want them to loop. Sub-steps are steps nested in loops.
How to use the "Move" toolbar to create a loop
- Highlight the steps you wish to make a loop with by clicking the tick boxes.
- In the "Move" toolbar click loop.
- Click "Loop through data" to wrap the highlight steps in a loop.
# Select data to loop through
The loop will not repeat unless data has been set to loop through. There are two methods for setting the loop data:
How to select data
- Method one - In the loop step, set the "Loop through data" by clicking "Insert Data" and choosing the data you wish to loop through.
- Method two - Edit a "sub-step" of the loop and click "Insert Data"; the data you select will automatically be set as the "Loop through data".
Please note: loops will return an error if the data source is empty.
# Inserting sub-steps
Insert the steps you wish to repeat inside the loop using the "Add sub-step" button. Steps outside of the loop will not be repeated.
# Nesting loop steps
You can nest loops within loops up to five levels. However, three levels of nesting are generally sufficient to perform a complex automation.
# Output data from a loop
All "Loop through data" steps output a token that can pass data to other steps. The token comprises all data output by its substeps, assembled in a 2D array, essentially forming a table.
# Grouping data in a loop
You can group the output from many steps into a single token by nesting them inside a loop. Note that the loop step does not have to perform iterations.
# Ending a loop
The End loop step allows you to finish a loop prematurely. When combined with a control flow step, you can use logic to determine when to finish your loop. This can be useful if you wish to loop until a certain condition is met, or not met.
# Loop design patterns
Design pattern: Loop through links scraping data
- 1 Read data from a Google Sheet
- 2 Loop through data
- 2.1 Go to page
- 2.2 Get data from bot's current page
- 2.3 Write data to a Google Sheet
- 2.4 Delete row from Google Sheet
Design pattern: Data entry into web form
- 1 Read data from a Google Sheet
- 2 Loop through data
- 2.1 Go to page
- 2.2 Enter text
- 2.3 Press keys
- 2.4 Click element
- 2.5 Delete row from Google Sheet
Design pattern: AI web scraper
- 1 Read data from a Google Sheet
- 2 Loop through data
- 2.1 Go to page
- 2.2 Get data from bot's current page
- 2.3 Extrcat data with ChatGPT
- 2.4 Write data to a Google Sheet
- 2.5 Delete row from Google Sheet
If you are looking for in-depth guides, take a look at these examples of bots using loops.
# Loop using the "Jump to another step"
In the step finder, you will also find the "Jump to another step" step. This performs a simple loop based on two parameters: the step to jump to and the number of cycles to complete.
# Using the "Jump to another step"
The best way to utilize this step is after completing a series of steps that you wish to repeat.
How
- Insert the "Jump to another step".
- In "Jump to step", enter the step number to which you want to return and repeat the process.
- Set the desired number of repetitions in "Maximum cycles".
That's it! However, remember that if you change the order of the steps, you may need to edit the "Jump to" value.
# Loop using the "Conditionally jump to another step"
Just like the loop step, you create a loop by specifying the step you wish to jump to. However, you have the added ability to add a condition. This is useful for creating an automation that behaves differently if a condition is true or false. We use this step in tandem with scrape steps to check for buttons or text values.
# How to Use the "Conditionally jump to another step"
How
- Click "Data to check" and choose the data you wish to check your condition against. This could be scraped data or data read from a Google Sheet.
- Next, under "Condition to check", add a value you can compare—strings and numbers are acceptable. Advanced users can also use JavaScript.
- Set your rules, i.e., match to one word or all words.
- In "Jump to step", enter the step number to which you want to return and repeat the process.
- Set the desired number of repetitions in "Maximum cycles".
- In "Reverse condition", choose to jump if the condition is true or false.