title: What is the most appropriate way to assign and test a variable in an if statement?
body: <p>Of the following, which is the preferred way of doing things, and why? Are there any specific situations in which it makes any difference, <strong>assuming that the function bar() does not take the value zero at any time</strong>?</p>
  
  <p>Case 1: Test the truth value of both conditions</p>
  
  <pre><code>if ((foo = bar()) &amp;&amp; foo &lt; 0)
      error();
  </code></pre>
  
  <p>Case 2: Test only the assigned variable</p>
  
  <pre><code>if ((foo = bar()) &lt; 0)
      error();
  </code></pre>