title: What is the most efficent for loop bounds checking
body: <p>Of the two following for loop implementations which should run faster or are they equal?</p>
  
  <p>This one:</p>
  
  <pre><code>for(int i=0; i&lt;objectPtr-&gt;bound; i++){
  
  //do something that has no affect on objectPtr-&gt;bound
  
  }
  </code></pre>
  
  <p>Or this one:</p>
  
  <pre><code>int myBound = objectPtr-&gt;bound;
  
  for(int i=0; i&lt;myBound; i++){
  //do something that has no effect on objectPtr-&gt;bound or myBound
  }
  </code></pre>
  
  <p>My hunch is the latter is faster but there could be some part of the compilation process that I don't understand that makes them equal in speed. I think the former will have to do an address resolution each loop cycle to determine if the value has changed. </p>
  
  <p>Is there some c++ syntax that can be used to let the compiler know that the value/bound will not change. I know volatile lets the compiler know that the value will always have the possibility of changing so could I use const int for the objectPtr->bound variable to get the compiler to not always check its value each loop iteration?</p>