title: Whats the best way to conditionally control the direction of a for loop
body: <p>I've got a block in my code in which the for loop should run forwards or backwards depending on a condition. </p>
  
  <pre><code>if (forwards) {
      for (unsigned x = 0; x &lt; something.size(); x++ ) {
          // Lots of code
      }
  
  } else {
      for (unsigned x = something.size()-1 ; x &gt;= 0 ; x-- ) {
          // Lots of code
      }
  } 
  </code></pre>
  
  <p>Is there a nice way to set this up, so I don't repeat all the code within the for loop twice?</p>
  
  <p>The 'something' in question is a std::vector&lt;>, so maybe its possible with an iterator? 
  (I'm not using C++11 )</p>