# /for

Usage:

/FOR variable start end commands

The variable will take on all numeric values between start and end, inclusive. The commands will be executed once for each of the values. If end is less then start, commands will not be executed.

Commands are executed in a new evaluation scope. This means, for example, that a /for called from a macro must use "`%%{...}`" and "`%%;`" instead of "`%{...}`" and "`%;`" to have the substitutions performed when the /for is expanded instead of when the calling macro is expanded.

Example:

Given the definition

      /def countdown = /for i 0 %{1} say $$[%{1} - i]

then the command "`/countdown 10`" would cause you to execute the commands "say 10", "say 9", ... "say 0". Note that the "`%{1}`" is substituted when /countdown is expanded, and the "$$" is replaced with "$". The resulting "$[10 - i]" is substituted when /for is expanded. If /countdown used "$[...]" instead of "$$[...]" in the commands, it would be substituted when /countdown is expanded, and you would repeat "10" 11 times. If /countdown used "%%{1}" or "{1}" instead of "%{1}" inside the expression, it would not be substituted until /for was expanded, so it would have the value of /for's first argument (the string "i", which has numeric value 0), and you would end up counting down from 0 to -10.

See: /while

Back to index
Back to tf home page

Copyright © 1995, 1996, 1997, 1998, 1999, 2002, 2003, 2004 Ken Keys