Functionality - Combining Loops
Summary
You can use for & while loops together in steps & actions.
This page has examples & explanations for common combinations.
Important
Combining loops can cause unexpected behaviour - see usage notes for more.
Examples
Loop Step until Selection
This example has a single step containing 3 actions.
The step will loop over a list of users until the Task Operator selects one.
Both a for loop & while loop are used, & are supplied to the same step.
Loop Parameters
The sequence is supplied using the previously saved user_list
variable.
The until condition will be met when the select
variable is True.
Behaviour
Each time the step runs, the:
- Next user in
user_list
is displayed in a table - Task Operator chooses whether to select the user or not
- Decision is saved as the
select
variable (True or False)
When a user is selected, the:
- New variable
selected_user
is created by eval (using a sequence value) - While loop completes, ending the step
Example
Loop Until Confirmation
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
|
Important Usage Notes
Multiple Loop Completion
Steps & actions will stop repeating when any of their loops is complete.
The effects of each loop completing in this example are explained below.
While Loop (expected)
This happens when a user is selected by the Task Operator.
It's the expected outcome, & the selected_user
variable is created OK.
For Loop (unexpected)
The sequence of users runs out if none is selected by the Task Operator.
It's an unexpected outcome, & the selected_user
variable isn't created.
If a selection is required, the next step could fail the task with exit & an exit code.