HomeManualTopicsTypesSymbols
std_types::generic_list/std::for_each
iterates over all items of the list
Parameters
- self
- the list to iterate over
- body
- the statement sequence to execute for each item
- finally (default: next)
- called after all items have been iterated over
Results
None
Description
For each item the statement sequence supplied as body is called with one or two arguments (depending on body's parameter count).
If called with two arguments the first argument is the position number of the item within the list.
To start the next iteration of the loop a tail call to the next-function has to be performed.
The loop is exited when the end of the loop is reached without calling the next-function.
This is a sequential loop.
Example
$persons list("Peter" "Mary" "Paul" "John" "David" "Emma")
for_each persons: (person)
writeln! person
next
Output
Peter
Mary
Paul
John
David
Emma
Example
$persons list("Peter" "Mary" "Paul" "John" "David" "Emma")
$total_length 0
$hash_sum 0
for_each persons
: (person)
plus &total_length length_of(person)
plus &hash_sum hash(person)
next
-> !total_length !hash_sum
writeln "total length: " total_length
writeln "hash sum: " hash_sum
Output
total length: 26
hash sum: 17062575543
Topic
Lists
Implements
See also