@node Foreach, Format, Fft, Commands @iftex @syntax Foreach. @end iftex @example Syntax: FOREACH variable ( list ) @{ commands @} FOREACH variable @{ list @} @{ commands @} FOREACH variable WORD @{ commands @} @end example @pindex Foreach In the first two forms, the value of @code{variable} is set to each element of list in turn, and then the commands are executed. An example would be @example FOREACH var ( alpha 2 gamma ) @{ WRITE STANDARD $var @} @end example @noindent which would write @code{alpha}, @code{2}, and then @code{gamma} to the terminal (@pxref{Loops and If}). The form with @{@} can be useful if you want the list exactly as you type it, for example @example FOREACH f @{ 0.1 $date @} @{ echo $f @} @end example @findex foreach, element in a vector The form FOREACH @code{variable} WORD ... is used to iterate over a vector, either arithmetic or string. For example, @example SET str=@{Sorbus Aucuparia David Monger@} FOREACH f str @{ echo $f @} @end example It is often useful to define the FOREACH variable to be LOCAL (@pxref{Define}), e.g. DEFINE @code{f} LOCAL in the last example.