Swift - Half-Open Range Operators



Swift includes two range operators, which are shortcuts for expressing a range of values. Following table shows these two operators.

Operator Description Example
Closed Range (a...b) defines a range that runs from a to b, and includes the values a and b. 1...5 gives 1, 2, 3, 4 and 5
Half-Open Range (a..< b) defines a range that runs from a to b, but does not include b. 1..< 5 gives 1, 2, 3, and 4
swift_operators.htm
Advertisements