title: What is the best alternative to calling strlen() in my for loop condition in C?
body: <p>I've read that it is bad practice to call strlen() in my for loop condition, because this is an O(N) operation.</p>
  
  <p>However, when looking at alternatives I see two possible solutions:</p>
  
  <pre><code>int len = strlen(somestring);  
  for(int i = 0; i &lt; len; i++)  
  {
  
  }
  </code></pre>
  
  <p>or...</p>
  
  <pre><code>for(int i = 0; somestring[i] != '\0'; i++)  
  {
  
  }
  </code></pre>
  
  <p>Now, the second option seems like it might have the advantage of 1) not declaring an unnecessary variable, and 2) should the string length be modified in the loop it should still reach the end as long as the length isn't &lt; i.</p>
  
  <p>However, I'm not sure.  Which one of these is standard practice among C programmers?</p>