Scripting reference · Nerdamer Language
each
Evaluates an expression once for each element of a vector, matrix, set or dictionary.
Each element is given the name you choose while the body runs. A matrix is visited row by row.
Scripting
each(container, value, body)
Write it in a script: nerdamer('block(total:0,each([1,2,3],x,total:total+x),total)'), or in the Playground.
Parameters
container- A vector, matrix, set or dictionary.
value- The name each element has inside the body.
body- The expression to evaluate for each element.
Examples
Add up a matrix, row by row.
block(s:0, each(matrix([1,2],[3,4]),v,s:s+v), s)
// → 10Open in Playgroundbreak() works here too: stop at the first element above 2.
block(s:0,each([1,2,3,4],v,block(if(v>2,break(),0),s:s+v)),s)
// → 3Open in PlaygroundGood to know
- The element name exists only inside the body.
