Next: Eval, Previous: Diagnostics, Up: Directives [Contents][Index]
Xenv
provides two looping constructs: $$loop
and
$$range
. Both allow you to repeat a block of text multiple
times on the output.
The $$loop
directive implements a foreach loop. The
syntax is:
$$loop name args... text $$end
Here, args is a whitespace-delimited list of words. When the
construct is scanned, args is subject to all kinds of expansions
and text is scanned verbatim. During expansion, the
$$loop
directive will assign each value from this list to the
variable name and expand text. Whatever value name
has before entering the loop will be restored after leaving it.
For example, the following construct:
$$loop X A B C This is $X $$end
will produce the following expansion:
This is A This is B This is C
The $$range
statement implements a for loop:
$$range name start stop [incr] text $$end
The three arguments are subject to expansions, whereas text is scanned verbatim. During expansion, the variable name is initialized with the value start and text is expanded. Then, the value of name is incremented by the value of incr and expansions continue until the stop value is reached (inclusive).
If incr is not given explicitely, +1 is assumed if
stop > start
and -1 is assumed otherwise.
For example:
$$range X 1 4 Number $X $$end
expands to:
Number 1 Number 2 Number 3 Number 4