Why is `while ((ch = getchar()) != EOF)` the common idiom?
<p>Why is </p>

<pre><code>while ((ch = getchar()) != EOF) {
   // stuff
}
</code></pre>

<p>more common/preferred/considered better than the following?</p>

<pre><code>ch = getchar();
while (ch != EOF) {
    // stuff
    ch = getchar();
}
</code></pre>

<p>I can think of some reasons for and against.</p>

<p>For:</p>

<ul>
<li>Shorter. </li>
<li>Everything is done in the condition.</li>
<li>Can't forget to rewrite the condition before the loop and at the end
of the loop.</li>
</ul>

<p>Against:</p>

<ul>
<li>Confusing.</li>
<li>An assignment in a loop (confusing? Messy?).</li>
<li>A potentially uninitialised variable in the loop's condition (it gets
assigned, but this may not be immediately obvious).</li>
<li>Comparison and assignment are kept neatly separated maintaining a
"one line, one task" mentality in the second format.</li>
<li>For every assignment there will be one comparison, so the complexity
in both cases will be the same, hence the easier to understand form
should be preferred.</li>
</ul>

<p>Are there other examples where a similar structure is used?</p>

<p>I have the feeling that this question will elicit opinions, so I would ask that they be backed up with some sort of reason. A cursory search revealed no duplicates to this question, so I hope it's not a duplicate!</p>