title: Why the contents of queue are shown when I use "for loop" but not when I use "while loop"?
body: <p>I want to display the contents of a queue in C++, so I decided to copy the queue into a temporary one and then display the elements of the new queue repetitive pop operations. But the following code shows output only when I use the <code>for</code> loop. </p>
  
  <pre><code>#include&lt;iostream&gt;
  #include&lt;queue&gt;
  using namespace std;
  
  int main()
  {
      queue&lt;int&gt; Q;
      queue&lt;int&gt; dump = Q;
  
      Q.push(1);
      Q.push(2);
      Q.push(3);
      Q.push(4);
  
      // for (dump = Q; !dump.empty(); dump.pop())   //THIS WORKS
      //     cout &lt;&lt; dump.front() &lt;&lt; '\n';
  
      while(!dump.empty())              //THIS DOES NOT
      { 
          cout &lt;&lt; dump.front() &lt;&lt; '\n';
          dump.pop();
      }
  }
  </code></pre>