I have a for each with a list of string array variable and item as currentItem.
In the body, I have a multiple assign as follows:
Int32 = strArray.Length
Int32 = Int32 + 1
Message Box: currentItem
This displays the strings as names. I want to display them as integers like 0, 1, 2, 3 on every iteration.
To display the strings as integers (0, 1, 2, 3, etc.) during each iteration of the “For Each” loop in UiPath, you can make use of the loop index. Here’s an updated version of your workflow:
- Keep the “For Each” loop with the list of string array variable and the item as currentItem.
- Add an integer variable before the “For Each” loop, let’s call it
index. Set its initial value to 0.
- Inside the loop body, perform the following steps:
- Assign the value of
index to a new integer variable, let’s call it
- Increment the value of
index by 1.At this point, you should have the current string item in the
currentItem variable, and the corresponding iteration index in the
- Display the
iterationIndex variable using the Message Box activity instead of the
currentItem variable. This will show the integers (0, 1, 2, 3, etc.) during each iteration of the loop.
you can also try this Create a Output variable for each and change the variable datatype to int32
as the output varaible starts from idex=0 and place a message inside for each it will display all the values like 0,1,2,3 until the items in array was completed…
This is not iterating. It results in showing 0 for every loop.
Can you please verify the scope of the variable IterationIndex? It’s most likely to be the Body. If yes, please change the scope to For Each.
Hope this helps,
i’ts in the Main Sequence most top.
What is iterationindex? is it the variable assign to the index in for loop?
Are you specifically looking to design the flow in this structure or your objective is just to get the output 0,1,2,3… on every iteration?
You don’t display an integer. Everything you display is displayed as a string.
My objective is to iterate through a list of string array names and then query them one by one from the entity database and extract an ID for each that will later need to be concatenated into a single string.
The below is where the iteration of numbers should take place. This should be replaced by a variable.
I usually use the repeat number of times activity as I’m more used to it in iteration but for now, I need the For Each.
IterationIndex has no value by default. It’s a int32 type.
As youa re not incrementing or changing the value it is showing or writing zero always…the default value for int type is 0
Please correct me if I’m wrong. In order to match the LocationName with the LocationArray(IterationIndexNumber), you are trying to increment the number like 0,1,2,3 on each iteration, right?
Since you are already iterating through the LocationArray in For Each, you don’t have to access the element like LocationArray(0) or like that. Just try using
Hope this helps,
Yes you’re right. I know I can do that but I simply want to learn how to iterate using Integers in for each loop.
with zero and without zero is not iterating
In that case, instead of assigning an Index outside the loop & trying to tweak it inside the loop again, you can follow this simple step.
Go to the For Each property panel, identify the
Index property & create a new variable there. That variable will be a zero based index variable will work perfectly in sync with the iteration.
You are not incrmeneting the index value …
Because in your multiple assign youa re first giving index value as 0 then adidng 1 which make sit 1 always as iterationindex is 0
So ideally your index value is 1 always for every iteration
can you show a small example as its not iterating still.
In the message box, instead if IterationIndex, just give
Index.ToString. It will give you the desired output.
it shows as 3 3 twice. I have two strings in the array for demo purposes.