title: Why does this code work but the other version does not?
body: <p>Specifically, the code is a solution to <strong>Exercise 1-9</strong> in K&amp;R <em>C Programming Language 2nd Edition</em>. I already solved it, but I have a question.</p>
  <blockquote>
  <p>Write a program to copy its input to its output, replacing each string of one or more blanks by a single blank.</p>
  </blockquote>
  <p>This code works and returns the desired output</p>
  <pre><code>int ch, last;
  
  for (last = 0; (ch = getchar()) != EOF; last = ch)
      if (ch == ' ' &amp;&amp; last == ' ')
          ;
      else
          putchar(ch);
  </code></pre>
  <p>This version of the code doesn't work and instead prints literally the same input with excess spaces included.</p>
  <pre><code>int ch, last;
  last = 0;
  
  while ((ch = getchar()) != EOF)
      if (ch == ' ' &amp;&amp; last == ' ')
          ;
      else
          putchar(ch);
      
      last = ch;
  </code></pre>
  <p>Could somebody tell me the difference between these two versions of code and why the latter version doesn't work?</p>