title: Modulus in a PHP loop
body: <p>I'm currently checking whether an entry in a loop is the third iteration or not, with the following code:</p>
  
  <pre><code>&lt;?php for ($i = 0; $i &lt; count($category_news); $i++) : ?&gt;
  
      &lt;div class="grid_8"&gt;
          &lt;div class="candidate snippet &lt;?php if ($i % 3 == 2) echo "end"; ?&gt;"&gt;
              &lt;div class="image shadow_50"&gt;
                  &lt;img src="&lt;?php echo base_url();?&gt;media/uploads/news/&lt;?php echo  $category_news[$i]['url']; ?&gt;" alt="Image Preview" width="70px" height="70px"/&gt;
              &lt;/div&gt;
                 &lt;h5&gt;&lt;?php echo $category_news[$i]['title']?&gt;&lt;/h5&gt;
              &lt;p&gt;&lt;?php echo strip_tags(word_limiter($category_news[$i]['article'], 15)); ?&gt;&lt;/p&gt;
              &lt;?php echo anchor('/news/article/id/'.$category_news[$i]['news_id'], '&amp;gt;&amp;gt;', array('class' =&gt; 'forward')); ?&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;?php if ($i % 3 == 2) : ?&gt;
           &lt;/li&gt;&lt;li class="row"&gt;
      &lt;?php endif; ?&gt;
  
  &lt;?php endfor; ?&gt;
  </code></pre>
  
  <p>How can I check if the loop is in its second and not its third iteration?</p>
  
  <p>I have tried <code>$i % 2 == 1</code> to no avail.</p>