title: Next iteration in `each` loop
body: <p>I have a collection:</p>
  
  <pre><code>@monday = HomeTask.where(:class_room =&gt; current_user.class_room, :day =&gt; 'Понеділок').order(created_at: :desc)
  </code></pre>
  
  <p>The <code>@monday</code> variable contains data from the database. In view, I show all dates from the collection:</p>
  
  <pre><code>&lt;% @monday.each_with_index do |mnd, i| %&gt;
    &lt;% if mnd.data == mnd.data[i + 1] %&gt;
      &lt;%= link_to 'nice' %&gt;
    &lt;% else %&gt;
      &lt;%= link_to 'ohhh...' %&gt;
    &lt;% end %&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>Within <code>if</code> body, I want to refer to the next element. But it does not work. In C++, to refer to the next element in the first iteration, it would be coded like this:</p>
  
  <pre><code>if(array[i] == array[i+1])
  </code></pre>
  
  <p>How do I use <code>each</code> in Ruby?</p>