Loop action
Use the Loop action in a task sequence to make your process repeat a series of actions before it goes on to the next action in your design. Loop actions can be used to try a specific action at a specific number of times before giving up and moving on.
Loop action examples
You can create flow logic with the Loop action in several ways, including:
- Loop through items in a collection
Loop through items in a collection applies to the actions inside the loop to each item of a collection of variables. For example, the actions inside the loop might add 2 and then multiply by 3. If you looped through a collection of five integers, then the loop would add 2 to the first integer, multiply the sum by 3, and put the product back into the first integer's slot in the collection. The loop would do the same actions on the second integer, then the third, fourth, and fifth. When it finished with the last item in the collection, the loop would "exit" and your process would move forward to the next action in your process design.
- To loop through items in a collection, specify the length of that collection as maximum loop count and then access the items in that collection with the current index on each iteration of the loop.
- Loop until a fixed count is reached
Loop until a fixed count is reached applies the actions inside the loop for a number of times that you specify. For example, if you specify 10, then the loop will run 10 times before moving forward to the next action in your process design.
- Loop while a condition is true
Loop while a condition is true applies the actions inside the loop as long as a certain condition is true, such as an integer value being greater than zero. You use the Expression Editor dialog box to construct the condition.
- To specify a condition, you can put a Decision action within the Loop action and use an Exit Loop action when the condition is met.
Name | Description |
---|---|
Name | Add a descriptive label for the action. |
Loop Count | Use the + or – buttons to set the number of time to repeat the sequence of commands. |
Current Index Data Name | Use to track the current loop count, starting at 0 for the first loop and then by increments by 1 each time. |
To add a Loop element to a task:
- Drag the Loop action from the task editor Toolbox to the desired location in your task.
- In the Name field, add a meaningful name to describe the item.
- In the Loop Count field, use the + or – buttons to set the number of times to repeat the sequence of commands.
- In the Current Index Data Name, type the label to identify the variable on tasks.
- Add the desired variable inside the loop action.
- Continue building the task per your flow design.