title: do-while infinite loop with if c++
body: <p>In this loop the user should enter an <code>int</code> and program checks if it be odd it will go to next parts, but I can't understand why if the user enter a character that's not <code>int</code>, the program is falling in an infinite loop!</p>
  
  <pre><code>int num;
  do {
      cout &lt;&lt; "PLEASE enter the num: ";
      cin &gt;&gt; num;
      if (num % 2 == 0)
          cout &lt;&lt; "Number should be odd!" &lt;&lt; endl;
      else
          break;
  } while (true);
  //...
  </code></pre>
  
  <p>Cause anyway <code>char/int != 0</code> and if it be <code>==0</code> too it should stop at next <code>cin</code> but it wont stop!
  I tried <code>ws(cin)</code> too but it didn't help me.
  Please tell me how I can fix that problem, and why that's happening.</p>