title: JSTL Count the ForEach loop
body: <p>I am trying to print some message for every 4 items in the List of items</p>
  
  <pre><code>&lt;c:forEach items="${categoryList}" var="category" varStatus="i"&gt;
      &lt;c:if test="${i%4 == 0}"&gt;
          &lt;c:out value="Test" /&gt;
      &lt;/c:if&gt;
      &lt;div class="span3"&gt;
          &lt;c:out value="a" /&gt;
      &lt;/div&gt;
  &lt;/c:forEach&gt;
  </code></pre>
  
  <p>But I am getting below exceptions, seems like <code>i</code> is not treated as number</p>
  
  <pre><code>java.lang.IllegalArgumentException: Cannot convert javax.servlet.jsp.jstl.core.LoopTagSupport$1Status@3371b822 of type class javax.servlet.jsp.jstl.core.LoopTagSupport$1Status to Number
      at org.apache.el.lang.ELArithmetic.coerce(ELArithmetic.java:407)
      at org.apache.el.lang.ELArithmetic.mod(ELArithmetic.java:291)
      at org.apache.el.parser.AstMod.getValue(AstMod.java:41)
      at org.apache.el.parser.AstEqual.getValue(AstEqual.java:38)
  </code></pre>
  
  <p>How do I achieve this? </p>
  
  <p>One way is to declare a variable and increment for every loop with the help of scriplets. But I would like to avoid this!</p>