|REBOL 3 Docs||Guide||Concepts||Functions||Datatypes||Errors|
|TOC < Back Next >||Updated: 10-Aug-2010 Edit History|
Evaluates a block for every value in a series.
word [word!] - Word that refers to the series, set to each position in series
body [block!] - Block to evaluate each time
The forall function moves through a series one value at a time.
The word argument is a variable that moves through the series. Prior to evaluation, the word argument must be set to the desired starting position within the series (normally the head, but any position is valid). After each evaluation of the block, the word will be advanced to the next position within the series.
cities: ["Eureka" "Ukiah" "Santa Rosa" "Mendocino"] forall cities [print first cities] Eureka Ukiah Santa Rosa Mendocino
chars: "abcdef" forall chars [print first chars] a b c d e f
When forall finishes the word is reset to the starting position of the series.
chars: next "abcdef" "bcdef"
forall chars  chars "bcdef"
The result of forall is the result of the last expression of the block:
chars: "abcdef" forall chars [first chars] #"f"
Or the result of a break/return from the block:
chars: "abcdef" forall chars [break/return 5] 5
The forall function can be thought of as a shortcut for:
[ original: series while [not tail? series] [ x: (your code) series: next series ] series: original :x ]
|TOC < Back Next >||REBOL.com - WIP Wiki||Feedback Admin|