title: Multiple conditions in a C 'for' loop
body: <p>I came across this piece of code. I generally use '&amp;&amp;' or '||' to separate multiple conditions in a <code>for</code> loop, but this code uses commas to do that.</p>
  
  <p>Surprisingly, if I change the order of the conditions the output varies.</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  
  int main() {
      int i, j=2;
  
      for(i=0; j&gt;=0,i&lt;=5; i++)
      {
           printf("%d ", i+j);
           j--;
      }
      return 0;
  }
  </code></pre>
  
  <p>Output = 2 2 2 2 2 2</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  
  int main(){
      int i, j=2;
  
      for(i=0; i&lt;=5,j&gt;=0; i++)
      {
           printf("%d ", i+j);
           j--;
      }
      return 0;
  }
  </code></pre>
  
  <p>Output = 2 2 2</p>
  
  <p>Can somebody explain the reason? It seems to be checking only the last comma-separated condition.</p>