Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Syntax

forEach($var, set, script)

ArgumentTypeDescription
$var$-VariableA $-Variable which will be set to each item in set in turn before script is processed.
setArray or RecordsetThe set of items which will be iterated over.
script$-VariableA comma separated list of Expressions which will be processed once for each entry in set.

forEach() is like every other function in that it returns a value. In this case the value returned is an Array of the results of running script for each entry in set. Note that the result of running the script is the value of the last script item to be processed before the the next iteration 

  • Its return value is the last statement executed in the last iteration.
  • All the $-variables used in the call to forEach() keep their values between iterations.
  • All the $-variables used in the call to forEach() will be available after it has returned.

Examples


In the first two examples, let

$numberList = [1,2,3,4,5,6,7,8,9,10]

...



Code Block
forEach($number, $numberList, 

   $currentValue = $number

),

...

Code Block
forEach($number, $numberList,  

   $sumOfNumbers = $sumOfNumbers + $number

)

Returns 55, as the variable $sumOfNumbers persists in-between forEach iterations.


Detailed example: (step-by-step)

...

Then the next attribute might be NonBusinessCustNumber, and you could write the number of non-business customers calculated in the loop to this attribute simply using the expression:

$nonBusiness

See Also