Not a developer? Go to MovableType.com

Documentation

For

Many programming languages support the notion of a "for" loop. In the most simple use case one could give, a for loop is a way to repeatedly execute a piece of code n times.

Technically a for loop advances through a sequence (e.g. all odd numbers, all even numbers, every nth number, etc), giving the programmer greater control over the seed value (or "index") of each iteration through the loop.

Attributes:

  • var (optional)

    If assigned, the current 'index' of the loop is assigned to this template variable.

  • from (optional; default "0")
  • start

    Identifies the starting number for the loop.

  • to
  • end

    Identifies the ending number for the loop. Either 'to' or 'end' must be specified.

  • step (optional; default "1")
  • increment

    Provides the amount to increment the loop counter.

  • glue (optional)

    If specified, this string is added inbetween each block of the loop.

Within the tag, the following variables are assigned:

  • __first__

    Assigned 1 when the loop is in the first iteration.

  • __last__

    Assigned 1 when the loop is in the last iteration.

  • __odd__

    Assigned 1 when the loop index is odd, 0 when it is even.

  • __even__

    Assigned 1 when the loop index is even, 0 when it is odd.

  • __index__

    Holds the current loop index value, even if the 'var' attribute has been given.

  • __counter__

    Tracks the number of times the loop has run (starts at 1).

Example:

    <mt:For from="2" to="10" step="2" glue=","><$mt:Var name="__index__"$></mt:For>

Produces:

    2,4,6,8,10
Back

Leave a Comment