cin condition checking error
<p>I am a beginner programmer learning c++. I am having a nagging issue with the cin command.
In the program section below, if I enter a wrong type at the 1st cin command, the program will not execute any of the following cin commands at all, but will execute the rest of the program. </p>

<pre><code>//start
#include &lt;iostream&gt;
using namespace std;
int main()
{
    int x=0;
    cout &lt;&lt; endl &lt;&lt; "Enter an integer" &lt;&lt; endl;

    //enter integer here. If wrong type is entered, goes to else
    if (cin &gt;&gt; x){
            cout &lt;&lt; "The value is " &lt;&lt; x &lt;&lt; endl;
    }
    else {
         cout &lt;&lt; "You made a mistake" &lt;&lt; endl; //executes
         cin.ignore();
         cin.clear();
    }
    cout &lt;&lt; "Check 1" &lt;&lt; endl; //executes
    cin &gt;&gt; x;                  //skips
    cout &lt;&lt; "Check 2" &lt;&lt; endl; //executes
    cin &gt;&gt; x;                  //skips
    return 0;                  
}
//end
</code></pre>

<p>Instead of the if else, if i put the same concept in a loop
while (!(cin >> x))
the program goes into an infinite loop upon enterring a wrong input.
Please help me explain this phenomenon, as the text book i am following says the code typed above should work as intended.</p>

<p>Thank you</p>
