title: When is pre-decrement applied in a for loop?
body: <p>I am trying to implement <a href="http://cr.yp.to/salsa20.html" rel="nofollow">an algorithm that is specified using some C style pseudocode</a>. </p>
  
  <p>The bulk of the algorithm is a <code>for</code> loop:</p>
  
  <pre><code>for (i = 20;i &gt; 0;i -= 2) 
  {
      //...snip
  }
  </code></pre>
  
  <p>It is claimed that the loop runs <strong>ten</strong> times:</p>
  
  <blockquote>
    <p>The entire series of modifications is a series of 10 identical double-rounds.</p>
  </blockquote>
  
  <p>I've ported the algorithm to my own language, and my results do not match the test vectors. So i'm trying to pick apart the minutia of the C-language in order to figure out what i could be doing wrong. </p>
  
  <p>Perhaps the reason my code does not match the result of the test vectors is that it is supposed to only run <strong>nine</strong> times:</p>
  
  <pre><code>| i  | i -= 2 | i &gt; 0 | Perform iteration |
  |----|--------|-------|-------------------|
  | 20 | 18     | Yes   | Yes - 1           |
  | 18 | 16     | Yes   | Yes - 2           |
  | 16 | 14     | Yes   | Yes - 3           |
  | 14 | 12     | Yes   | Yes - 4           |
  | 12 | 10     | Yes   | Yes - 5           |
  | 10 |  8     | Yes   | Yes - 6           |
  |  8 |  6     | Yes   | Yes - 7           |
  |  6 |  4     | Yes   | Yes - 8           |
  |  4 |  2     | Yes   | Yes - 9           |
  |  2 |  0     |  No   | No                |  
  </code></pre>
  
  <p>If i were to read the <code>if</code> statement logically, it is only executed nine times.</p>
  
  <p>There's still the confusion of why they say it runs <strong>ten</strong> rounds, but then use <strong>20</strong> as the initial value. </p>
  
  <p>I tried duplicating the logic i see (execute it one less times than documented), but my results still don't match. Unfortunately i don't have access to any functional code to compare my results against a known good implementation. So i may be barking up the wrong tree.</p>
  
  <p>Am i barking up the wrong tree?</p>