title: Practice of checking 'trueness' or 'equality' in conditional statements - does it really make sense?
body: <p>I remember many years back, when I was in school, one of my computer science teachers taught us that it was better to check for 'trueness' or 'equality' of a condition and not the negative stuff like 'inequality'.</p>
  
  <p>Let me elaborate - If a piece of conditional code can be written by checking whether an expression is true or false, we should check the 'trueness'.</p>
  
  <p>Example: Finding out whether a number is odd - it can be done in two ways:</p>
  
  <pre><code>if ( num % 2 != 0 )
  {
    // Number is odd
  }
  </code></pre>
  
  <p>or</p>
  
  <pre><code>if ( num % 2 == 1 )
  {
    // Number is odd
  }
  </code></pre>
  
  <p><em>(Please refer to the marked answer for a better example.)</em></p>
  
  <p>When I was beginning to code, I knew that <code>num % 2 == 0</code> implies the number is even, so I just put a <code>!</code> there to check if it is odd. But he was like 'Don't check NOT conditions. Have the practice of checking the 'trueness' or 'equality' of conditions whenever possible.' And he recommended that I use the second piece of code.</p>
  
  <p>I am not for or against either but I just wanted to know - what difference does it make? Please don't reply 'Technically the output will be the same' - we ALL know that. Is it a general programming practice or is it his own programming practice that he is preaching to others?</p>
  
  <p><strong>NOTE:</strong> I used C#/C++ style syntax for no reason. My question is equally applicable when using the <code>IsNot</code>, <code>&lt;&gt;</code> operators in VB etc. So readability of the '!' operator is just one of the issues. Not THE issue.</p>