FOREACH Command

Repeating Commands

You can use the FOREACH command to create a group of commands to be executed repeatedly. You can use the command to iterate over an array or set of tokens generated by a regular expression (regex).

If you define the FOREACH command as the outer command and need to specify commands within the FOREACH command, you can drag and drop the command under the FOREACH command. Note that the BREAK_FOREACH and CONTINUE_FOREACH commands work only in conjunction with the FOREACH command and cannot be used with other commands.

The FOREACH command supports the following two modes:

  • Array— Use this mode when you want to loop through all elements of an existing array.
    FOREACH Command 1
  • Tokenizer— Use this mode when you want to loop through all the parts of the initial string that match a specific rule.
    Foreach command 2

The Choose Source drop-down lists the variables that contain the input data. The Choose Target drop-down lists the variable that will store the results. The command matches the input data with the regex pattern defined in the Define a Pattern text box or the Delimiter Value that was provided, based on the preference.

For example, if the phone number that you enter is stored in the PhoneNumber string variable and is matched with the //(//d{3}//)//d{3}-//d{4} regex pattern. The pattern is matched only if the input string contains, say, (444)444-4444. The resulting value is stored in the ConvertedPhoneNumber as a string variable in the Choose Target drop-down.

To define a FOREACH command in ARRAY mode:

  1. In the Rule Editor, under the Rule tab, from the COMMANDS drop-down, drag and drop the FOREACH command to the Working Canvas.
  2. Optionally, in the Comment text box, enter any descriptive comments you want to include for the rule procedure you are defining.
  3. From the Choose Array Variable drop-down, select the required array variable.
  4. From the Choose Variable drop-down, select the variable with the same data type as the array's value. In each iteration, this variable contains the value of the current Array element.
  5. Click Ok.

To define a FOREACH command in the TOKENIZER mode:

  1. In the Rule Editor, under the Rule tab, from the COMMANDS drop-down, drag and drop the FOREACH command to the Working Canvas.
  2. Optionally, in the Comment text box, enter any descriptive comments you want to include for the rule procedure you are defining.
  3. From the Choose Source drop-down, select the string variable whose value will be parsed.
  4. From the Choose Target drop-down, select the string variable. In each iteration, this variable contains the current slice of the source string.
  5. Select either Pattern or Delimiter.
    • For Pattern, enter the required regex pattern in the Define a Pattern text box.
    • For Delimiter, define a Delimiter value in the Delimiter Value text box.
  6. Click Ok.

The FOREACH command appears in the Working Canvas.