Search                        Top                                  Index
HELP FOREACH                                          SH JLC, July 1982

    foreach <pattern> do <actions> endforeach;
    foreach <pattern> in <list> do <actions> endforeach;

FOREACH is used for iteration over a database consisting of a list of

The <pattern> is matched (see HELP *MATCHES) against each element of the
database, which defaults to the value of the variable *DATABASE when the
IN <LIST> clause is omitted. After each successful match, the item that
matched the pattern is bound to the variable IT and the <actions> are

Usually, the match will have side-effected the value of some variables
in the pattern.
    vars x list;
    [[a is big] [b is small] [c is big] [d is small]] -> list;
    foreach [?x is big] in list do
        [therefore ^x is heavy] =>
    ** [a is big]
    ** [therefore a is heavy]
    ** [c is big]
    ** [therefore c is heavy]

See also HELP
   *MATCHES  - summary of the matcher
   *FOREVERY - like FOREACH, but matches a list of patterns against a
   *DATABASE - describes the use of the POP-11 DATABASE
   *LOOPS    - for other types of iteration
   *FOR      - iteration over lists and numbers