Template:For loop/doc

This template implements a for loop or a foreach loop.

This template calls a user-specified template (the "called template") multiple times: once for each value in either 1) an iterated sequence or 2) an explicit list. Each value in the sequence or list is passed to the same specified parameter of the called template (the "variable parameter"). Optionally, pre- and postfixes can be attached to the passed values.

In addition to the specified variable parameter, other parameters of the called template ("static parameters") can be given a value which is the same in each iteration.

Usage
Either option 1 (iteration parameters) or option 2 (an explicit list of values) may be used, but not both.

The first unnamed parameter, prior to any explicit values, is a separator. The separator is a string that is output between calls to the template named in. It is not output after the last call.

Caution

 * The separator can be prefixed with "1=", but in that case it cannot contain newlines and spaces at the start and end.
 * If any parameter value contains an equals sign, use (see Template Usage hints and workarounds).
 * If you use numbered parameters, note that the first value is parameter 2 (e.g. ), because parameter 1 is the separator.
 * If you use numbered parameters, you must not skip any numbers. The loop will terminate after the first absent numbered parameter. (Parameters can be blank, but not absent.)

Substitution
The current Lua-based template supports substitution. If no is not specified, then substituting the template will substitute everything, including the call to the template passed in call. If it is specified, then the template substitutes into a sequence of calls to the template specified.

Example: -> ,  ->

For full substitution Special:ExpandTemplates can also be used.

Other examples with explicit values
using 3x gives

gives

gives:

gives:

begin-><-end gives:

begin-><-end

Notes about legacy code
This template is currently in its third incarnation. It now uses the Lua code at Module:For loop. It was ported to Lua from ParserFunctions. There was also a previous version with a named "sep" parameter to specify the separator value. The template was originally based on Template:For on meta. The template name was changed because there was already a Template:For on Wikipedia.

The old versions were limited to 150 variable values and four fixed parameters. There are no such limits in the current version. Also, in the first version the "sep" parameter didn't allow whitespace in the separator value. This was fixed with the second version and was retained in the current version.