title: Is the for loop condition evaluated each loop in Swift?
body: <p>I have a small debate at work: Is it a good practice to calculate the size of the Array in swift before running over it's items? What would be a better code practice:</p>
  
  <p><strong>Option A:</strong></p>
  
  <pre><code>    func setAllToFalse() {
          for (var i = 0; i &lt; mKeyboardTypesArray.count; i++ ) {
              self.mKeyboardTypesArray[i] = false
          }
      }
  </code></pre>
  
  <p>or <strong>Option B:</strong></p>
  
  <pre><code>    func setAllToFalse() {
          let typesCount = mKeyboardTypesArray.count
          for (var i = 0; i &lt; typesCount; i++ ) {
              self.mKeyboardTypesArray[i] = false
          }
      }
  </code></pre>
  
  <p>All, of course, if I don't alter the Array during the loops.</p>
  
  <p>I did go over the documentation, which states this:</p>
  
  <blockquote>
    <p>The loop is executed as follows:</p>
    
    <p>When the loop is first entered, the initialization expression is
    evaluated once, to set up any constants or variables that are needed
    for the loop. The condition expression is evaluated. If it evaluates
    to false, the loop ends, and code execution continues after the for
    loop’s closing brace (}). If the expression evaluates to true, code
    execution continues by executing the statements inside the braces.
    After all statements are executed, the increment expression is
    evaluated. It might increase or decrease the value of a counter, or
    set one of the initialized variables to a new value based on the
    outcome of the statements. After the increment expression has been
    evaluated, execution returns to step 2, and the condition expression
    is evaluated again.</p>
  </blockquote>