While Loop

Executes a sequence of steps while a condition is still satisfied.

Description

This step is used to repeat a sequence of steps while a certain condition holds. For example, it can be used to allow a user to update a form based on the submitted input, or to retry authentication a certain number of times before offering a different method.

When the step is initiated, a loop condition is evaluated. If true, the sequence of steps is performed and then the condition is re-evaluated to determine if to perform another iteration. This process continues until either the condition is no longer satisfied (which progresses the journey to the next step) or the max number of iterations is reached (which fails the journey). The current iteration count is also stored in a variable, so it can be used in the loop condition or as a generic condition in the nested flow.

The nested control flow can include any journey step, except the Complete Journey step. If it includes a step that aborts the journey upon execution (e.g., Reject Access), the entire control flow will be aborted.

Configuration

Field Description
Loop Condition Condition to evaluate before each iteration of the loop, specified using an expression. A loop iteration will be executed only if this condition evaluates to true (and the maximum iteration count hasn't been reached). Default is true.
Fail After Max Iterations Maximum number of times the loop body can be executed for the current step, which cannot be greater than 100. If this limit is met but the loop condition still evaluates to true, the journey will be aborted. Default is 5.
Iteration Count Variable Name of the variable that stores the current number of iterations that were executed for the step, which can be used in the body of the loop in the step expressions (such as for defining the loop condition). The iteration count starts at 0.
Variables to Set A list of the additional variables to define, which can be used in the loop condition. The name represents the variable name and the expression will be used to yield the value to assign.

Example

Here are some examples of how this step can be used:

Example 1: While user isn't authenticated

Suppose we want to limit the number of unsuccessful authentication attempts before failing the journey. In our example, the loop body contains a sequence of steps for password authentication. The loop is configured to repeat as long as the user remains unauthenticated using !@policy.isUserAuthenticated(), with up to 5 retries before failing the journey.

Example 2: While iterations is less than X

Suppose we want to limit the number of unsuccessful authentication attempts before offering a different method. In this example, the loop body contains a sequence of steps for password authentication. The loop is configured to store the current iteration count in a variable named attempts, and to stop when either the user successfully authenticates or exceeds 3 retries using attempts<3 && !@policy.isUserAuthenticated().