[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.6.13 FOR - Emit a template block multiple times

This macro has a slight variation on the standard syntax:
 
FOR <value-name> [ <separator-string> ]
or
 
FOR <value-name> (...Scheme expression list

The first argument must be the name of an AutoGen value. If there is no value associated with the name, the FOR loop block is skipped entirely. The scope of the FOR function extends to the corresponding ENDFOR macro.

If there are any further arguments, if the first character is either a semi-colon (;) or an opening parenthesis ((), then it is presumed to be a Scheme expression containing the FOR macro specific functions for-from, for-by, for-to, and/or for-sep. See section 3.4 AutoGen Scheme Functions. Otherwise, the remaining text is presumed to be a string for inserting between each iteration of the loop. This string will be emitted one time less than the number of iterations of the loop. That is, it is emitted after each loop, excepting for the last iteration.

If the from/by/to functions are invoked, they will specify which copies of the named value are to be processed. If there is no copy of the named value associated with a particular index, the FOR template block will be instantiated anyway. The template must use methods for detecting missing definitions and emitting default text. In this fashion, you can insert entries from a sparse or non-zero based array into a dense, zero based array.

NB: the for-from, for-to, for-by and for-sep functions are disabled outside of the context of the FOR macro. Likewise, the first-for, last-for and for-index functions are disabled outside of the range of a FOR block.

 
[+FOR var (for-from 0) (for-to <number>) (for-sep ",") +]
... text with various substitutions ...[+
ENDFOR var+]

this will repeat the ... text with various substitutions ... <number>+1 times. Each repetition, except for the last, will have a comma , after it.

 
[+FOR var ",\n" +]
... text with various substitutions ...[+
ENDFOR var +]

This will do the same thing, but only for the index values of var that have actually been defined.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated by Bruce Korb on January, 7 2002 using texi2html