title: Modulus optimization in a program
body: <p>I have seen that many people prefer to use in code:</p>
  
  <pre><code> while(i&lt;1000000){
         ret+=a[i];
         i++;
         if(ret &gt;= MOD) 
            ret -= MOD;
     }
  </code></pre>
  
  <p>instead of making <code>ret%MOD</code> in the final step.</p>
  
  <p>What is the difference between these two and how both these are equal?</p>
  
  <p>How it is making an optimize our code?</p>