{|LOOP|ITERATOR}  {/|LOOP|}

Loops are the method by which you iterate through your report display elements.

#loop through each month in our report result

{|LOOP|RESULT.MONTH_OF_YEAR}

  <tr>

    <th>{MONTH_OF_YEAR.NAME}</th>

    <td>{MONTH_OF_YEAR.TOTAL_COUNT}</td>

  </tr>

{/|LOOP|}



Loops may be nested within each other:

#loop each year

{|LOOP|NESTED.YEAR(SORT=ORDER_NUM)}

  <tr>

    <th>{YEAR.NAME}</th>

    <td></td>

    <td>{COUNT(YEAR,YEAR)}</td>

  </tr>

  #for each year, loop each month of the year

  {|LOOP|YEAR.MONTH_OF_YEAR(SORT=ORDER_NUM)}

  <tr>

    <th></th>

    <td>{MONTH_OF_YEAR.NAME}</td>

    <td>{COUNT(MONTH_OF_YEAR)}</td>

  </tr>

  {/|LOOP|}

{/|LOOP|}


Loops have several helpful attributes.



{ITERATOR.NUMELEMENTS}

Displays the number of elements that the iterator contains.


<div class='numrecs'>
{RESULT.MONTH_OF_YEAR.NUMELEMENTS} records found
</div>



This can be useful in conjunction with {|SHOWIF|} for only displaying content if some items were found.


{|SHOWIF|RESULT.MONTH_OF_YEAR.NUMELEMENTS}



It can also be useful to control the structure of a table:


<thead>
<tr>
<th class="bottom-title" rowspan="2">Year</th>
<th class="center-title"
colspan="{YEAR.MONTH_OF_YEAR.NUMELEMENTS}">
Months
</th>
</tr>
<tr>
{|LOOP|YEAR.MONTH_OF_YEAR(SORT=ORDER_NUM)}
<th>{MONTH_OF_YEAR.NAME}</th>
{/|LOOP|}
</tr>
</thead>
<tbody>




Column headers that need to span multiple sub-headers can make use of the TIMES suffix:


<th colspan="{YEAR.MONTH_OF_YEAR.NUMELEMENTS.TIMES(2)}">
Months
</th>



{LOOP.ISFIRST}

Evaluates to TRUE the first time through the loop. This is useful for displaying headers.


{|CROSSTAB|}
<div>
{|LOOP|CROSSTAB.YEAR(SORT=ORDER_NUM)}
    #only display the table header
    #the first time through the loop

   {|SHOWIF|LOOP.ISFIRST}
<table class='data'>
<thead>
<tr>
<th>Name</th>
{|LOOP|YEAR.MONTH_OF_YEAR(SORT=ORDER_NUM)}
<th>{MONTH_OF_YEAR.NAME}</th>
{/|LOOP|}
</tr>
</thead>
<tbody>
{/|SHOWIF|}
...
{/|LOOP|}
</div>
{/|CROSSTAB|}



{LOOP.HASNEXT}

Evaluates to TRUE if there is another item in the loop after the current one. This is useful for displaying report footers, summary totals, and list delimiters.


{|CROSSTAB|}

<div>

  {|LOOP|CROSSTAB.YEAR(SORT=ORDER_NUM)}

    ...        

    #only display the table footer the 

    #last time through the loop

    {|VANISHIF|LOOP.HASNEXT}

        </tbody>

      </table>

    {/|VANISHIF|}

  {/|LOOP|}

</div>

{/|CROSSTAB|}

<tr id="crosstab-top-5-groups-row-{LOCATION_GROUPS.ID}">

  <th>{LOCATION_GROUPS.NAME}</th>

  {|LOOP|LOCATION_GROUPS.REGIONS}

    <td>

      {AVG(REGIONS.SCORE).NUMBERFORMAT(2)}

    </td>

    #Only display summary totals 

    #the last time through the loop

    {|VANISHIF|LOOP.HASNEXT}

      <td>

        {AVG(REGIONS.SCORE, LOCATION_GROUPS).NUMBERFORMAT(2)}

      </td>

      <td>

        {COUNT(REGIONS, LOCATION_GROUPS)}

      </td>

    {/|VANISHIF|}

  {/|LOOP|}
</tr>



{LOOP.COUNT([OFFSET])}

Indicates what position in the loop we’re at. Good for displaying row numbers.


{|LOOP|CROSSTAB.MONTH_OF_YEAR}

<tr>

  #display row count

    <th>{LOOP.COUNT}</th>    

    <th>{MONTH_OF_YEAR.NAME}</th>                

    {|LOOP|MONTH_OF_YEAR.DAY_OF_WEEK}

      <td>{COUNT(DAY_OF_WEEK)}</td>

    {/|LOOP|}

</tr>

{/|LOOP|}





By default, COUNT starts at 1. However, you can adjust the count by providing an optional argument.


#subtract one from the count, starts at 0
{LOOP.COUNT(-1)}
#add one to the count, starts at 2
{LOOP.COUNT(1)}



{LOOP.COUNTMOD(DIVISOR)}


Evaluates to the loop’s position modulo the divsor (i.e., the remainder when the position is divided by the divisor).


This is useful for alternating formats when used in conjunction with conditionals.


{|LOOP|RESULT.DATAPOINTS}

  #alternate class for odd/even rows

  <tr class="{LOOP.COUNTMOD(2)?odd-row:even-row}">

    <th>{LOOP.COUNT}</th>

    <th>{DATAPOINTS.DATAPOINT_ID}</th>

    <td>{DATAPOINTS.TRENDING_TIMESTAMP.FORMATTED(m/d/Y)}</td>

    <td>{DATAPOINTS.MONTH_OF_YEAR.NAME}</td>

    <td>{DATAPOINTS.SCORE}</td>

  </tr>

{/|LOOP|}