title: for in loop with where clause in Swift
body: <p>I have tried to update a little function to Swift 2.1. The original working code was:</p>
  
  <pre><code>import func Darwin.sqrt
  func sqrt(x:Int) -&gt; Int { return Int(sqrt(Double(x))) }
  
  func sigma(n: Int) -&gt; Int {
      // adding up proper divisors from 1 to sqrt(n) by trial divison
      if n == 1 { return 0 } // definition of aliquot sum
      var result = 1
      let root = sqrt(n)
      for var div = 2; div &lt;= root; ++div {
          if n % div == 0 {
              result += div + n/div
          }
      }
      if root*root == n { result -= root }
      return (result)
  }
  print(sigma(10))
  print(sigma(3))
  </code></pre>
  
  <p>After updating the for loop I get a runtime error for the last line. Any idea why that happens?</p>
  
  <pre><code>import func Darwin.sqrt
  func sqrt(x:Int) -&gt; Int { return Int(sqrt(Double(x))) }
  
  func sigma(n: Int) -&gt; Int {
      // adding up proper divisors from 1 to sqrt(n) by trial divison
      if n == 1 { return 0 } // definition of aliquot sum
      var result = 1
      let root = sqrt(n)
      for div in 2...root where n % div == 0 {
              result += div + n/div
      }
      if root*root == n { result -= root }
      return (result)
  }
  print(sigma(10))
  print(sigma(3)) //&lt;- run time error with for in loop
  </code></pre>