C++ using precalculated limiters in for loops
<p>In scripting languages like PHP having a for loop like this would be a very bad idea:</p>

<pre><code>string s("ABCDEFG");
int i;
for( i = 0; i &lt; s.length(); i ++ )
{
   cout &lt;&lt; s[ i ];
}
</code></pre>

<p>This is an example, i'm not building a program like this. (For the guys that feel like they have to tell me why this piece of code &lt;<em>insert bad thing about it here</em>>)</p>

<p>If this C++ example was translated to a similar PHP script the lenght of the string would be calculated every loop cycle. That would cause an enormous perfomance loss in realistic scripts.</p>

<p>I thought the same would apply to C++ programs but when I take a look at tutorials, several open-source libraries and other pieces of code I see that the limiter for the loop isn't precalculated.</p>

<ul>
<li>Should I precalculate the lenght of the string <code>s</code>?</li>
<li>Why isn't the limiter always precalculated? (seen this in tutorials and examples)</li>
<li>Is there some sort of optimization done by the compiler?</li>
</ul>
