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

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."
}

See also