title: How is Java's for loop code generated by the compiler
body: <p>How is Java's for loop code generated by the compiler?</p>
  
  <p>For example, if I have:</p>
  
  <pre><code>for(String s : getStringArray() )
  {
     //do something with s
  }
  </code></pre>
  
  <p>where <code>getStringArray()</code> is a function that returns the Array I want to loop on, would function be called always or only once? How optimal is the code for looping using this construct in general?</p>