studio
2024.10
true
UiPath logo, featuring letters U and I in white

Studio User Guide

Last updated Dec 19, 2024

Example of Using a For Each Activity

To exemplify how to use a For Each activity, let’s create an automation that goes through each element of an array of integers and writes the length of the array and each element to the Output panel.

  1. Create a new sequence.
  2. Create an array of integer variables, FibonacciNumbers.
  3. In the Default field, type the Fibonacci sequence up to a desired value, such as {1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89}.
  4. Add a For Each activity in the Designer panel.
  5. Do not make any changes to the ForEach field.
  6. In the In field, add the FibonacciNumbers variable. This activity looks at each individual item in the provided variable.
  7. In the Body section of the For Each activity, add a Write Line activity.
  8. On the right side of the Text field, select Plus docs image > Open in Advanced Editor.
  9. Inside the Expression Editor window, type "The length of this Fibonacci sequence is " + FibonacciNumbers.Length.ToString + " and contains the " + item.ToString + " element.". This expression enables you to write the total number of array elements and each element of the array in the Output panel.

    The final project should look as in the following screenshot.



  10. Press F5. The automation is executed. Note that the Output panel displays the correct message for each element of the array.
    Note: The Length property enables you to find out the total number of array elements.


Was this page helpful?

Get The Help You Need
Learning RPA - Automation Courses
UiPath Community Forum
Uipath Logo White
Trust and Security
© 2005-2024 UiPath. All rights reserved.