title: Why does this condition in a while loop get executed as though it were part of the loop body?
body: <p>Here's the relevant function (this example is taken from <a href="https://msdn.microsoft.com/en-us/library/wwbyhkx4(v=vs.94).aspx" rel="nofollow">here</a>): </p>
  
  <pre><code>​function factorial (num) {
    if (num &lt; 0) {
      return -1;
    }
    else if (num == 0) {
      return 1;
    }
  var tmp = num; 
    while (num-- &gt; 2) {
      tmp = tmp * num;
    }
  return tmp;
  }
  console.log(factorial(8));
  ----&gt; 40320
  </code></pre>
  
  <p>As I was studying how this function works (and got stumped on the operator precedence in the expression <code>(num-- &gt; 2)</code>; kudos to my mentor Edwin Calte at MakerSquare for pointing that out), I noticed that the <code>num</code> variable decrements even though this decrementation is something that is stipulated as a precondition for the loop body to be executed and is not itself part of the loop body. I could understand why it would do that if the expression read instead like: </p>
  
  <pre><code>while (num-- &gt; 2) {
  num--;
  ...}
  </code></pre>
  
  <p>In the above example, that second <code>num--</code> isn't necessary for it to work. Another similar expression where this <em>doesn't</em> seem to happen when I run it in my devtools console is:</p>
  
  <p>​<code>if (x - 2 == 5) { x-- }</code></p>
  
  <p>Here, it seems that if x is 7 then x will decrement by 1, ​<strong>not</strong>​ that if x is 7 then 2 will be subtracted from x, and then x will decrement by 1. But in the above example with ​<code>num</code>​, the latter principle is what takes effect.</p>
  
  <p>Could someone please explain why?</p>