title: How to get a zero-based count in a Velocity foreach loop
body: <p>I am trying to get a zero-based counter in a Velocity <code>#foreach</code> directive.</p>
  
  <p>if i use:</p>
  
  <pre><code>#foreach ($item in $list)
     item.getName() : $velocityCount
  #end
  </code></pre>
  
  <p>i will get:</p>
  
  <pre><code>Fred : 1
  Wilma : 2
  Barney : 3
  </code></pre>
  
  <p>But i need:</p>
  
  <pre><code>Fred : 0
  Wilma : 1
  Barney : 2
  </code></pre>
  
  <p>The solution must be as simple as possible from the velocity template's point of view.</p>
  
  <p><strong>EDIT</strong>:<br/>
  I can use:</p>
  
  <pre><code>#foreach ($item in $list)
     #set( $num = $velocityCount - 1 ) //The white space in mandatory
     item.getName() : $num
  #end
  </code></pre>
  
  <p>and it works. But I'm looking for a more elegant solution.</p>
  
  <p><strong>EDIT 2</strong>:<br/>
  I need the one-based counter to be available too. That is, in the same template i will most likely have one <code>#foreach</code> directive that will require a zero-based counter and another <code>#foreach</code> directive that requires a one-base counter.</p>