FOREACH


control
Since v1.0.0
Available on all platforms
See also

Configuration parameters


The FOREACH function implements a for loop on a list or map.

For each iteration i on a list, the i-th element on the list is put on top of the stack, and the exec macro is then called.

For each iteration i on a map, the exec macro is called with the i-th value on top of the stack, and the i-th key just below on the stack. You can start your macro with 'value' STORE 'key' STORE.

Signature

Examples

// define macro <% 2 ** %> 'SQUARE' STORE // FOREACH loop { 1 -2 3 -4 5 -6 } $SQUARE FOREACH
{ 'audi' 35 'dacia' 342 'renault' 200 'porsche' 14 } 'brandcountMAP' STORE 0 'total' STORE //total count 'Sum of following car makers : ' $brandcountMAP <% 'value' STORE 'key' STORE $total $value + 'total' STORE //add value to total count. $key + ' ' + //concatenate brands on the stack %> FOREACH '= ' + $total TOSTRING + //concatenate the total to the string on the stack