Variable array

I wanna arrange variables in some “Array”

like “C” programing

like this…
Variable_Array = {variable1, variable2, variable3, …}

and use variables sequentially with Loop

like this…
for(i = 0 ; i < 10 ; i++)
{
Variable_Array[i];
}

Of course, there are many follow activities.
but, if i can’t use “Loop” i have to add so… soooo many activities… : (

i hope your help… really

1 Like

Create variable of data type as array.
Use assign activity to initialize array
Eg. array1={var1,var2,var3}
Here, array1 is the name of array
var1,var2 and var3 are the name of variables
Use for each loop to access each item of array.

2 Likes

Hi
Welcome to uipath community
—in the studio we got a variable panel at the bottom of the screen
— there create a variable of type array of string and name the variable as str_array (if we are trying to create a variable with a array of type STRING, we can choose others as well like int32, Boolean anything)
— and give a default value like
New String(){size}
Size means number of elements in the array we need like
New string(){3} /// which can have three elements in it

— now use a for each loop activity and pass the above variable as input and in the property panel (at the right side of the screen) of the for each loop activity change the type argument as string and pass the input as str_array
—now to see the value of each element in the array we can use a write line activity and mention like
item.ToString
Where item is a variable obtained from the for each loop which has the element of the array

—or if we don’t want to use for each loop but would still like to see the value of array we can use a while loop with a condition like
str_array.count < counter
Where counter is a variable of type int32 defined in the variable panel with a default value as 0
—now inside the loop we can use a write line this
str_array(counter).ToString
Which will print the value of array at each index one by one
— next to this write line activity use a assign activity like
counter = counter + 1
— this is done to increment the value of counter so that when iterating with while next element will be displayed in the write line activity

Simple isn’t it
Hope this would help you
Cheers @98995169

3 Likes

Hi @98995169

Here some example for your reference. See image below
1.Declare your variable as an array of string just shown in the image below.
2.Create a foreach to iterate in the array of string and make work on it the way you desire! just shown in image below.

cheers :smiley:

Happy learning :smiley:

2 Likes

@98995169 I think the example from @pattyricarte is exactly the way to do it for you exact example. The only thing I would add is that UiPath doesn’t have a native for loop, so if you want to iterate through it in a different way then you can still do so with a for each loop. Just loop through an Enumerable.Range giving it the parameters necessary. For example Enumerable.Range(0,9) would be the same as your for i = 0, i<10, i++ example. If you wanted to only iterate through the first 10 squares than you would change it to Enumerable.Range(0,9).Select(Function(x) x*x)

EDIT: I usually wouldn’t use things like the second one with the select function, but just wanted to show it’s an option. Generally I would use a normal enumerable.range and just have the very first thing in the loop to be an if condition and put in a ‘continue’ activity. E.g. I want to only go through even numbers I would put an if condition at the top of the for each checking if mod(item)=1 Then Continue

2 Likes