#81: Half-Open vs Closed Ranges in Swift

Swift has two very common range operators: ..< and ....

0..<3  // 0, 1, 2
0...3  // 0, 1, 2, 3

The half-open form is especially common in collection code because collection counts naturally work with an exclusive upper bound.

When iterating over indices or slicing arrays, ..< is usually the safer default.


I'm also on Twitter and GitHub.

Subscribe via RSS.