Skip to main content
Introduction to Foreach

Process development

Ossi Galkin avatar
Written by Ossi Galkin
Updated over 7 months ago

Foreach

The Foreach Element takes in an Expression that should be of type IEnumerable, for example a List or an Array []. Each item in the Expression will be executed in sequence.

The Element also has a Variable parameter which can be used inside the Foreach scope iteration with #var. reference. This is the value of the current item in the iteration. The default value for this is i which can be referenced with #var.i reference.

Another variable that is available inside the foreach scope is #var.(iteration_variable_name)_index which contains the current iteration index of the Expression input. For instance, if the Foreach iteration variable is set to theawsomeiterator, the iteration index would be referenced with #var.theawsomeiterator_index.

The return value of a Foreach scope is a list of the return values for each iteration. The return values are ordered in the same way as the provided list.

Example of usage

In the example above, the Foreach Element would be used to iterate over a list of users to send email. The list of users contains the email address per user. The foreach user Element would be configured to have Expression #result[get a list of users] in order to iterate over the list of users and Variable user used as the iterator variable. In the Foreach Element send email to user the email would be sent to an address referred with #var.user.email for example.

The next article is Introduction to While


โ€‹

Did this answer your question?