Loop package

Use the Loop package to repeat a set of actions multiple times based on specified conditions. It allows you to iterate over a list, a range of numbers, or until a specific condition is met, making it useful for tasks that require repetitive actions.

For instance, repeat the set of actions that read data from each row of a Microsoft Excel file, rename all files in a folder, and save each email in a mailbox. You can also use the If action within the Loop action to validate a condition, and based on the outcome of it, skip the current iteration in the loop or even break the loop. For more information on using the If action, refer to the If package documentation.

For conditional loops, different actions are taken depending on whether the conditional parameters are met. For loops that have a specified number of iterations, the loop exits on the last iteration and goes to the next step in the bot.

When you run a sequence of actions repeatedly for a specific number of times within a loop, the end condition within the loop is evaluated in every iteration. For instance, consider the following scenario where you loop through a Data Table with 10 columns.
  • You enter the dynamic values of the column count as the end condition in the loop.
  • Inside the loop body, use the Data Table > Delete column action to delete the column at index 0.
  • When you run the bot, it deletes a column in each iteration.
As a result, this reduces the iteration count because the loop's end condition is evaluated during every iteration.
Note: You can run the bots with a maximum number of 97 nested loops.

Labeling loops for automation control

Loop labels are used to identify and manage different loops within a bot. They help in distinguishing between multiple loops, especially when dealing with nested loops. Loop labels make it easier to control the flow of automation by allowing you to specify which loop to continue, break, or exit. This is beneficial in complex automation scenarios where multiple loops are involved.
Note: To add loop labels, ensure that you build your bots using Loop package version (3.7.4). This feature is not backward compatible.
To add labels to the Loop, Continue, or Break actions, in the Label field, specify a label to identify your loop.
Note:
  • Ensure that each loop label in a specific bot is unique.
  • The Label field supports only alphanumeric characters.
The following example describes how to use the Label field to break or continue a loop in a bot:
  • In the Label field of the first Loop action, specify a label as outerloop.
  • In the Label field of the second Loop action, specify a label as innerloop.
  • In the Loop > Continue action, in the Label field, select the label of the loop from which you want to continue.
  • In the Loop > Break action, in the Label field, select the label of the loop from which you want to break.

Click the video to see how labeling loops work.

In a bot, if you have multiple nested loops with Loop > Continue and Break actions, and if you have not labeled the loops, then on bot execution, the bot breaks or continues the nearest loop by default.

For example, you have:
  • An outer loop and an inner loop nested within the outer loop.
  • A Loop > Continue and Break action within the inner loop.
If you have not labeled any of these loops, when you run the bot, the bot will break or continue the nearest loop (the inner loop).

Actions in the Loop package

The following Loop actions are available:

Action Description
Loop See Using Loop action.
Continue

See Continue action.

Break

See Break action.