title: C++ for loop: evaluation of condition
body: <p>I have got a (stupid?) C / C++ question about a loop:</p>
  
  <pre><code>for (size_t i = 0; i &lt; std::distance(begin, end); ++i) {
    a.push_back(i);
  }
  </code></pre>
  
  <p><code>begin</code> and <code>end</code> are two iterator. My question is, is <code>std::distance(begin, end)</code> calculated for each element in the loop? Or is it better to use this version:</p>
  
  <pre><code>size_t dist = std::distance(begin, end);
  for (size_t i = 0; i &lt; dist; ++i) {
    a.push_back(i);
  }
  </code></pre>