title: Why is my Swift loop failing with error "Can't form range with end < start"?
body: <p>I have a for loop that checks if a number is a factor of a number, then checks if that factor is prime, and then it adds it to an array.  Depending on the original number, I will get an error saying</p>
  
  <blockquote>
    <p>fatal error: Can't form range with end &lt; start</p>
  </blockquote>
  
  <p>This happens almost every time, but for some numbers it works fine.  The only numbers I have found to work with it are 9, 15, and 25.</p>
  
  <p>Here is the code:</p>
  
  <pre><code>let num = 16 // or any Int
  var primes = [Int]()
  
  for i in 2...(num/2) {
  
      if ((num % i) == 0) {
          var isPrimeFactor = true
  
          for l in 2...i-1 {
              if ((i%l) == 0) {
                  isPrimeFactor = false;
              }//end if
          }//end for
  
          if (isPrimeFactor == true) {
              primes.append(i)
          }//end if
  
      }//end if
  
  }//end for
  </code></pre>