For Each

Verb: foreach

Cycles through a collection and assigns the value of each item in it to a variable. The variable's value is replaced on each iteration.

Syntax

foreach --collection(List<Variant>) --variable(Variant) [--distinct(Boolean)]

Inputs

Script Designer Required AcceptedTypes Description
--collection Collection Required List<Any>, Stack<Any>, Queue<Any>, String Dictionary<Any>, Email Connection, Error, Text File Reader, Workflow Batch Collection cycled through
--variable Variable Required Any Variable to use in the iteration.
--distinct Distinct Optional Boolean Option used to assign repeated values within the Collection to the Variable only once.

Example

Example 1: Cycles through a Queue collection and displays the values assigned to the variable during the execution, with the Distinct option enabled.

defVar --name collectionCycledThrough --type Queue --innertype String --value "[a,b,c,a]"
defVar --name valueCycledThrough --type String
foreach --collection "${collectionCycledThrough}" --variable "${valueCycledThrough}" --distinct
	logMessage --message "${valueCycledThrough}" --type "Info"
endFor
//Result:
//a
//b
//c

Example 2: Similar to the previous example, but this time the Distinct option is disabled.

defVar --name collectionCycledThrough --type Queue --innertype String --value "[a,b,c,a]"
defVar --name valueCycledThrough --type String
foreach --collection "${collectionCycledThrough}" --variable "${valueCycledThrough}"
	logMessage --message "${valueCycledThrough}" --type "Info"
endFor
//Result:
//a
//b
//c
//a

See Also

  • Begin Do-While
  • Case
  • Continue
  • Else
  • Else If
  • End Case
  • End Do-While
  • End For Each
  • End If
  • End While
  • Execute Subroutines
  • For
  • Go to
  • Go to If
  • If
  • Insert Label
  • Interrupt Loop
  • Next
  • Otherwise
  • Return from Subroutine
  • Run Subroutine
  • Run Subroutine If
  • Then
  • When
  • While