title: Iterating through all but the last index of an array
body: <p>I understand that in Swift 3 there have been some changes from typical C Style for-loops. I've been working around it, but it seems like I'm writing more code than before in many cases. Maybe someone can steer me in the right direction because this is what I want:</p>
  
  <pre><code>let names : [String] = ["Jim", "Jenny", "Earl"]
  for var i = 0; i &lt; names.count - 1; i+=1 {
      NSLog("%@ loves %@", names[i], names[i+1])
  }
  </code></pre>
  
  <p>Pretty simple stuff. I like to be able to get the index I'm on, and I like the for-loop to not run if names.count == 0. All in one go.</p>
  
  <p>But it seems like my options in Swift 3 aren't allowing me this. I would have to do something like:</p>
  
  <pre><code>let names : [String] = ["Jim", "Jenny", "Earl"]
  if names.count &gt; 0 {
      for i in 0...(names.count - 1) {
          NSLog("%@ loves %@", names[i], names[i+1])
      }
  }
  </code></pre>
  
  <p>The if statement at the start is needed because my program will crash in the situation where it reads: for i in 0...0 { }</p>
  
  <p>I also like the idea of being able to just iterate through everything without explicitly setting the index:</p>
  
  <pre><code>// Pseudocode
  for name in names.exceptLastOne {
      NSLog("%@ loves %@", name, name.plus(1))
  }
  </code></pre>
  
  <p>I feel like there is some sort of syntax that mixes all my wants, but I haven't come across it yet. Does anyone know of a way? Or at least a way to make my code more compact?</p>
  
  <p>UPDATE: Someone suggested that this question has already been asked, citing a SO post where the solution was to use something to the degree of:</p>
  
  <pre><code>for (index, name) in names.enumerated {}
  </code></pre>
  
  <p>The problem with this when compared to Hamish's answer is that I only am given the index of the current name. That doesn't allow me to get the value at index without needing to do something like:</p>
  
  <pre><code>names[index + 1]
  </code></pre>
  
  <p>That's just one extra variable to keep track of. I prefer Hamish's which is:</p>
  
  <pre><code>for i in names.indices.dropLast() {
      print("\(names[i]) loves \(names[i + 1])")
  }
  </code></pre>
  
  <p>Short, simple, and only have to keep track of names and i, rather than names, index, and name.</p>