title: swift EXC_BAD_INSTRUCTION error in playground
body: <p>I have the following test code...</p>
  
  <pre><code>import Foundation
  
  var n = 5
  
  let binSlots = 64
  var numOfOnes = 0
  var inSequence = false
  
  func toThePower(number: Int, power: Int) -&gt; Int {
      var ans = number
      for _ in 1..&lt;power  {
          ans = ans * number
      }
      return ans
  }
  
  // the following line is fine
  if n &lt;= toThePower(number: 2, power: 4) {
      print("ok")
  }
  
  for i in stride(from: binSlots, through: 0, by: -1) {
      // the following line produces this error:
      // // error: Execution was interrupted, reason: 
      // EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0).
      let pCalc = toThePower(number: 2, power: i) 
  
      if n &gt;= pCalc {
          n = n - pCalc
          numOfOnes += 1
          inSequence = true
      }
      else {
          if inSequence {
              break
          }
      }
  }
  </code></pre>
  
  <p>Any clues as to what's causing the error? I know that if I comment out the following...</p>
  
  <pre><code>//    for _ in 1..&lt;power  {
  //        ans = ans * number
  //    }
  </code></pre>
  
  <p>the error goes away however I don't know why or why the first call to the function runs with no errors.</p>
  
  <p>I have looked at other similar posts but none was similar to my case.</p>
  
  <p>your help is appreciated.</p>
  
  <p>thank you.</p>