How To Use For Loop In Automation Anywhere

Introduction

This article describes how to use ‘For’ or ‘Iterator’ loop in Automation Anywhere using the community edition. In some circumstances, we need to do iteration based actions or iterate some file/data, so I will explain the same in this article.

If you are a beginner then need to check this article Getting Started Robotic Process Automation using Automation Anywhere to create environment of Automation Anywhere.

Create a New bot

After logging Automation anywhere account through cloud community edition link,

How to use For loop in Automation Anywhere

You will see a Dashboard as shown in below image and you can create a new bot through the highlighted button ‘create a bot’,

How to use For loop in Automation Anywhere

Bot Configuration

After clicking on ‘create a bot’ button, you will get a popup window. It will ask some information about bot which you want to create like-

  • Name of bot
  • Description of bot(optional)
  • Folder location of bot

How to use For loop in Automation Anywhere

After clicking on choose option, a popup window will come where you can browse ‘CSharpCorner’ folder and click on choose to set a default location for your new bot.

How to use For loop in Automation Anywhere

After creating a bot, we will follow below steps-

  • Create Number variable
  • Assign value in Number variable
  • Add ‘Loop’ and configure it
  • Add ‘Increment’ action in Loop
  • Print Number Variable

Create Variables

Let’s create a variable to assign some value and do the increment in it within loop.

Create Number Variable: Create a variable through left side variable pane and click on ‘+’ sign, and select ‘Number’ type and name as ‘NumberVariable’ and click on create button.

How to use For loop in Automation Anywhere

Assign value in Number Variable

Now we will assign a value in Number Variable and to do so, we will go to ‘Action’ pane on left side and find ‘Number’ action. Drag & drop ‘Assign’ into workspace and fill below details-

  • Add value 15 in source number
  • Select ‘NumberVariable’ as destination variable

How to use For loop in Automation Anywhere

Add Loop and configure it

We will add loop to do some action with ‘NumberVariable’ like ‘Increment’ and to do so, we will go to ‘Action’ pane on left side and find ‘Loop’ action. Drag & drop ‘Loop’ into workspace and fill below details-

  • Select ‘Iterator’ option with ‘For n times’ option
  • Let’s select iteration times as 5 to execute it 5 times

How to use For loop in Automation Anywhere

Note: We can also use ‘For each’ through Iterator and ‘while’ loop but I will explain them in upcoming articles.

Add ‘Increment’ in Loop

Here we have to increase the value of ‘NumberVariable’ through ‘Increment’ action in loop so we will go to ‘Action’ pane on left side and find ‘Number’ action. Drag & drop ‘Increment’ into workspace and fill below details-

  • Select ‘NumberVariable’ as Number
  • Increment value with 1
  • Assign value in ‘NumberVariable’

How to use For loop in Automation Anywhere

Print Number Variable

At last, we will add ‘MessageBox’ through action pane to display ‘NumberVariable’ after conversion.

How to use For loop in Automation Anywhere

After running bot, we got the result as 20 because the initial value was 15 and we did increment with 1 value in 5 iterations that’s why output is 20.

How to use For loop in Automation Anywhere

Conclusion

In this article, how to use ‘For’ or ‘Iterator’ loop in environment of Automation Anywhere.


Recommended Ebook

Printing in C# Made Easy

Download Now!
Similar Articles