C++ while(cin >> x){} vs. while(true) {cin >>x;}
<p>Please consider this C++ code for creation and traversing a linked list (number of nodes to be decided by user, not programmer)</p>

<pre><code>#include &lt;iostream&gt;
using namespace std;
class Node
{ 
 public:
 int data; Node* next;
 Node(int d, Node* j): data(d),next(j) {cout &lt;&lt; "Constructor\n";}
};

int main()
{int n; Node* p; Node* q = 0;

while(cin &gt;&gt; n) 
{ p = new Node(n,q);
  q = p;}

for(;p-&gt;next; p=p-&gt;next)
    cout &lt;&lt; p-&gt;data &lt;&lt; "-&gt;";
    cout &lt;&lt; p-&gt; data &lt;&lt; "-&gt;*\n";
return 0;}
</code></pre>

<p>The code above works perfectly, and can be terminated by the user using Ctrl+D followed by Enter. However if we replace while(cin >> n) with while (true) using cin >> n; inside the loop, as shown here</p>

<pre><code>    while(true) 
    { cin &gt;&gt; n;
    p = new Node(n,q); q = p;}
</code></pre>

<p>then upon the user attempting to terminate, the loop just goes on automatically creating new Nodes!!  Why??
Thanks in advance</p>
