each
each <iterable> <block>
Run a block once for every element of an iterable, in order. Used for its side effects; it produces no useful value.
Arguments
<iterable>— a list or any iterable. A bare string is not iterable; convert it first withwords.<block>— a block taking one parameter. The parameter is declared inside the braces, right after{, and is bound to the current element on each pass.
Returns
null.
Control flow
Inside the block, continue skips to the next element,
break stops the iteration early, and
return returns from the enclosing handler or def.
Examples
after command (wave) {
each [creatures $self] { <bystander>
do "smile $bystander"
}
}
For each living creature in the owner's room, the mob smiles at that creature in turn — the body runs once per creature present.
Iterate the words of a string by converting it first:
each [words "north east south west"] { <dir>
do "say I could go $dir."
}