Function foreach
foreach varName aList aBlock
Executes a block of code for each of the elements in a list.
- Parameters:
- varName -
Symbol identifying a variable inside the code block
aBlock that that will take the value of each of the elements
in the list.
- aList -
A list of objects of any type.
- aBlock -
Block of code that will be executed for every element in
aList.
- Returns:
-
The result of the last execution of aBlock
or the null object if aBlock never is executed.
-
The foreach function executes aBlock
as many times as the number of elements in aList.
Every time aBlock gets executed a variable
identified by the symbol varName is initialized
inside aBlock with a reference to one of the
elements in aList, in the
same order they appear in aList.
If you ignore the return value you could define the
foreach function like this:
define foreach ( varName aList aBlock ) {
map [lambda ( $varName ) $aBlock] $aList
}
Report a bug or request new features
© 2002