FOREACH

REBOL Dictionary 2.0


Summary:

Evaluates a block for each value(s) in a series.

Usage:

foreach word data body

Arguments:

word - Word or block of words to set each time (will be local) (must be: get-word word block)

data - The series to traverse (must be: series)

body - Block to evaluate each time (must be: block)

Description:

For each evaluation of the block, the word will be set to the first value in the series. The WORDS argument can be a single word or a block of words.


    cities: ["Eureka" "Ukiah" "Santa Rosa" "Mendocino"]
    foreach city cities [print city]
    Eureka
    Ukiah
    Santa Rosa
    Mendocino


    chars: "abcdef"
    foreach char chars [print char]
    a
    b
    c
    d
    e
    f

Related:

for - Repeats a block over a range of values.
forall - Evaluates a block for every value in a series.
forskip - Evaluates a block for periodic values in a series.


<Back | Index | Next>

Copyright 2003 REBOL Technologies