When using Automate for robotic process automation (RPA), understanding how to use variables and loops is pivotal for creating efficient automation tasks. Let’s dive deeper into what these are and discover how to best use the advanced functionalities of variables and loops within Automate.
Not an Automate user yet? Download a free Automate trial to follow along.
Understanding Variables in Automate
Variables in Automate serve as placeholders for data that can be referenced and manipulated throughout your automation tasks. They allow for dynamic task execution, accommodating changing inputs and conditions.
Creating Variables
To create a variable in Automate:
- Navigate to the Task Builder.
- Select the "Task Variables" tab.
- Click on the "+" button to add a new variable, specifying its name, type, (e.g., string, number), and initial value.
Note: Variables can also be created directly within the task as well. These types of variables are considered local variables that are available only to the function that they are created within. Task variables provide an additional means of sharing common data within a single function or between more than one function. Always choose the variable type that is best for your task and its desired result.

Using Variables
Once created, variables can be used in various actions within your task. For example, you can:
- Store user input or data retrieved from applications.
- Perform calculations and store the results.
- Control flow based on variable values.

Mastering Loops in Automate
Loops are essential for repetitive tasks, enabling the automation workflow to perform a set of actions multiple times based on specified conditions.
Types of Loops
Automate supports several types of loops:
- Loop - Array: Loops through an Automate array, populating the specified variable with the current element.
- Loop - Break: Breaks out of a loop or if statement.
- Loop - Dataset: Loops through the rows of the dataset specified. With each successive loop a series of steps are executed, and the current row of the dataset is incremented. The loop ends when it reaches the end of the dataset or when a break is encountered.
- Loop – End loop: Marks the end of a block of steps that is to be looped by any of the Automate loop actions.
- Loop – Expression: Loops while or until the expression specified is true. With each successive loop, the expression is re-evaluated. The loop ends after the condition is met or when a break is encountered.
- Loop – File Contents: Loops through the contents of the specified text file and populates a variable with the current string of delimited text. The loop ends at the end of the file or if a break step is encountered.
- Loop – Files: Loops through the files contained in a folder and populates a variable with the current file name. With each successive loop, the next file name is retrieved. The loop ends after all the file names have been retrieved or when a break is encountered. This action accepts wildcards (that is, * and ?).
- Loop – List: Loops through items in a list (comma, carriage return, or other delimited text). With each successive loop a block of steps is executed, and the current index variable is updated with the next item in the list. The loop ends when at the end of the list or when a break is encountered.
- Loop – List control: Loops through the items of a list box or list view and populates a variable with the current item text. With each successive loop, the next item is retrieved. The loop ends after all the elements have been browsed or when a break is encountered.
- Loop – Processes: Loops through the file names of the processes (applications) that are currently running on the system and populates a variable with the file name of the current process. With each successive loop, the next process file name is retrieved. Optionally, a dataset can be populated with extended process information. The loop ends after all the process file names have been retrieved or when a Break is encountered.
- Loop – Range: Loops through the range of numbers specified. With each successive loop, a block of steps is executed. An index variable can optionally update the current loop count. The loop ends after the counter has reached the specified number or when a break is encountered.
- Loop – Tree Control: Loops through the items of a tree view. The specified variable is updated with the current item text. With each successive loop, the next item is retrieved. The loop ends after all the elements have been browsed or when a break is encountered.
- Loop – Windows: Loops through all the windows that are currently open on the system. The specified variable is updated with the current window title. With each successive loop, the next window title is retrieved. The loop ends after the window title of all the open windows have been retrieved or when a break is encountered.
Implementing a Dataset Loop
To implement a Dataset Loop:
- In the Task Builder, select the "Loop" action.
- Choose "Dataset" from the available actions.
- Specify the dataset to iterate over.
- Define the actions to be performed during each iteration.

Combining Variables and Loops
Variables and loops can be combined in Automate to build even more efficient automated tasks. For example, you can use a variable to store an index value and update it within a loop to process items in a list sequentially.
Example Scenario: Processing a List of Files
Consider a scenario where you need to process a list of files in a directory:
- Create a variable to store the directory path.
- Use a "Loop: Files" action to retrieve the list of files and store it in a variable.
- Implement a For Each Loop to iterate through the file list.
- Within the loop, use actions to open, read, and process each file.

More Best Practices for Using Variables and Loops
- Naming Conventions: Use descriptive names for variables to enhance readability and maintainability.
- Scope Management: Define the appropriate scope for variables to ensure they are accessible where needed without causing conflicts.
- Efficiency Considerations: Minimize the number of loop iterations and actions within loops to optimize performance.
Looking for More RPA Training?
Explore opportunities for additional RPA training offered by Fortra—from on-demand tutorials to more personalized one-on-one training.