Versions Compared

Key

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

...

ArgumentTypeDescription
$var

$-variable

A $-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.: 

  • Its return value is a list containing the last statement executed in each 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.

...

Use in Conjunction With

  • continue, will continue to the next item in the set.
  • break, will break out of the forEach loop. 

Examples


In the first two examples, let

...

Returns 55. The forEach will return the value at each iteration ([1, 3, 6, 10, 15, 21, 28, 36, 45, 55]), the do then returns the final value of $sumOfNumbers.

Detailed example: (step-by-step)

Code Block
forEach( $customerType, customers.type, 

   $total = $total + 1, 

   if( $customerType == "Business", continue() ), 

   $nonBusiness = $nonBusiness + 1, 

   subString($customerType, 1, 6) 
)

...