Show TOC

Background documentationLoop Expression

 

A loop expression processes a set of rules on a given context for a number of times. The number of repetitions for executing the rules is defined by a numeric constant, a condition, or by iterating over the rows of a table. The expression can also contain exit conditions as well as continue conditions for the rules. The loop expression can either return a result that can be used for further processing or trigger actions.

Features

Processing Mode

A loop expression can be executed in either of the following processing modes:

  • Perform Action

    In this processing mode, the system automatically assigns the predefined Actions table object as result data object. After loop processing has finished, this table returns the list of all actions that have been triggered by the loop expression.

  • Return Value

    In this processing mode, you can assign any kind of data objects as the expression's result data object. If you use this setting, it is up to you to make sure that the rules processed at runtime make changes to the value of the selected data object.

Loop Mode

You can choose between the following loop modes to further specify how exactly the loop expression shall operate:

  • Repeat ... Times

    For this mode, you must specify a number indicating the number of iterations that the loop shall run through. You choose this loop mode for use cases where you know in advance the exact number of iterations needed. The only way for a so-defined loop expression to run through less iterations than defined is that an optional exit condition is fulfilled.

    Example Example

    You need to calculate a one-year-ahead forecast of sales numbers for a particular product. This forecast shall be broken down by month. To accomplish this, you define a loop expression of type Repeat ... Times with a fixed iteration number of 12 to calculate the numbers for each month of the year ahead from now.

    End of the example.
  • Do ... Until ...

    For this mode, you have to define a cancellation criterion that must be fulfilled to make the loop expression stop processing. The cancellation criterion is tested after each iteration. This means that in a Do ... Until ... loop, the rules that have been defined for the expression are processed at least once.

  • While ... Do ...

    For this mode, you have to define a continue criterion that must be fulfilled for the loop expression to continue processing. The continue criterion is tested before each iteration. This means that in a While ... Do ... loop, the rules that have been defined for the expression may not be processed at all.

  • For Each Entry In ...

    In this mode, the number of iterations depends on the number of entries in a table that shall be used as the loop iteration controller. The object that you select as a controller must be either a table data object or an expression that has a table data object assigned as its result data object. This is the case, for example, for several of the table operation subtypes, or for a decision table or search tree expression in multiple match mode. The number of iterations can be further restricted by additional selection criteria that you may define for the table.

    The iteration controller object can be freely selected from all suitable objects in the system. It is not necessary to include that object in the expression context.

Caution Caution

For the Do ... Until ... and the While ... Do ... loop mode, it is up to you to make sure that the cancellation or continue criterion is updated and evaluated during each iteration. Otherwise, the system might be caught in an infinite loop and must be terminated manually.

End of the caution.

Note Note

If you have defined the loop control conditions and decide to change the loop mode afterwards, the reference to the involved objects as well as the additional selection criteria you may have defined are deleted immediately from the loop expression. Once you have saved the expression with the new loop mode, the only way to recover the previous settings is to revert to an older version. This is possible, of course, only under the condition that versioning is turned on for the loop expression.

End of the note.
Loop Conditions

For all loop modes, you can define additional exit or continue conditions for each of the rules to be processed during one iteration. By doing so, you can override the loop behavior as defined by the loop mode. Conditions enable you to make the loop processing dependent not only on the iteration counter but on any kind of additional test criteria, as long as the test result is expressed in a boolean value. For example, you may test in a condition if the current user is authorized to perform a particular rule, if the current date and time lies within a predefined validity period, if the number of articles passed to the loop context qualifies for additional discount calculations, and so on.

  • Exit condition

    With an exit condition, you can perform any additional tests. If the test result is True, processing of the entire loop expression is cancelled.

  • Continue condition

    With a continue condition, you can perform any additional tests. If the test result is True, the current loop iteration is cancelled. Expression processing continues by increasing the iteration counter by 1 and executing the first rule in the rule sequence.