title: Comparing different types of C++ for-loops
body: <p>C++ is very flexible, and I want to understand for-loop operations more deeply. I'm hoping for a good comparison of each implementation and what is better/faster/more efficient. Additionally, it would be a perk to learn some other way of implementing a for-loop - and not necessarily something in the STL.</p>
  
  <p>I'm looking for expert answers, not opinions. Notice the many limitations I've put on answers: answers pertain only to the specific for-loops mentioned, their limitations (which may not be intuitive), specific alternatives not in the STL, and specific enhancements.</p>
  
  <p>How do these other for-loops (not the 'traditional') work differently/better? </p>
  
  <p>What are the limitations of the other 'non-traditional' for-loops?</p>
  
  <p>Example 1) Traditional for-loop is:</p>
  
  <pre><code>for(int i=0;i&lt;SIZE;i++){
      //do something for each iteration;
  }
  </code></pre>
  
  <p>Example 2) Now lets say I have a vector of scores.</p>
  
  <pre><code>vector&lt;int&gt; scores = {77,91,100,88,85,68,95};
  
  for (auto it = scores.begin(); it != scores.end(); ++it){
      //do something for each iteration;
  }
  </code></pre>
  
  <p>Example 3) Same scores vector, different loop.</p>
  
  <pre><code>for (auto&amp; x: scores) //do something for each iteration;
  </code></pre>
  
  <p>I'm particularly interested in example 3, because it is so simple, I'm not sure what it's actually doing, yet functionally is the same as the other two. </p>