title: Which is faster: while(1) or while(2)?
body: <p>This was an interview question asked by a senior manager.</p>
  <p>Which is faster?</p>
  <pre><code>while(1) {
      // Some code
  }
  </code></pre>
  <p>or</p>
  <pre><code>while(2) {
      //Some code
  }
  </code></pre>
  <p>I said that both have the same execution speed, as the expression inside <code>while</code> should finally evaluate to <code>true</code> or <code>false</code>. In this case, both evaluate to <code>true</code> and there are no extra conditional instructions inside the <code>while</code> condition. So, both will have the same speed of execution and I prefer while (1).</p>
  <p>But the interviewer said confidently:
  &quot;Check your basics. <code>while(1)</code> is faster than <code>while(2)</code>.&quot;
  (He was not testing my confidence)</p>
  <p>Is this true?</p>
  <h3>See also: <a href="https://stackoverflow.com/questions/2611246/is-for-faster-than-while-true-if-not-why-do-people-use-it">Is &quot;for(;;)&quot; faster than &quot;while (TRUE)&quot;? If not, why do people use it?</a></h3>