The For Tag

The "for" tag is a looping tag that allows looping between certain values with an optional increment value. This tag must contain a body.

Attributes

  • The "for" tag supports all base tag attributes.
  • The "for" tag supports all looping tag attributes. The varStatus attribute, exposes an object that, in addition to what all looping tags already expose, exposes additional "int" properties, "start", "end", and "step", as set by the corresponding attributes below.
  • start: int Required. This is the starting value.
  • end: int Required. This is the ending value. The loop processing will terminate when it has passed this value.
  • var: String Required. This is the name of the variable that is exposed in the beans map for reference in the loop.
  • step: int Optional. This specifies the increment to add between loops. It defaults to one, and it is an error for it to be zero. However, it can be negative. It is possible to loop zero times if "start" is greater than "end" and "step" is positive, or if "start" is less than "end" and "step" is negative. That is not an error. In that case, the block is removed, and content below is shifted up (or, content to the right is shifted left, depending on the "copyRight" attribute value).

Example

x x2
<jt:for start="10" end="0" step="-2" var="n">${n} ${n * n}</jt:for>

...gets transformed into...

x x2
10 100
8 64
6 36
4 16
2 4
0 0