title: Swift For Loops using Closed Range
body: <p>I have a <code>for</code> loop and want to access the 'current' index. Xcode is giving me irritating errors.</p>
  
  <pre><code>for k in [1...map.dates.count-1]
  {
      map.returns.append((map.closingPrices[k]-map.closingPrices[k-1])/map.closingPrices[k-1])
  }
  </code></pre>
  
  <p>So what I'm basically doing is <code>for k in [1..10]</code>, calculate the return (b-a)/a where b and a are contiguous elements in some array (<code>closingPrices</code>).</p>
  
  <p>The compiler has no issue with me using <code>k</code> to access <code>closingPrices</code> but it gets upset when I use <code>k-1</code> because k is not an integer, it is a <code>CountableClosedRange&lt;Int&gt;</code>.</p>
  
  <p>Error says </p>
  
  <blockquote>
    <p>Binary operator '-' cannot be applied to types CountableClosedRange and Int.</p>
  </blockquote>
  
  <p>So - simple question - how do I rewrite my code to access the integer value of k and substract 1 from it and not get a compiler error.</p>