A half-open interval over a comparable type, from a lower bound up to, but not including, an upper bound.
Language
- Swift
Overview
You create Range instances by using the half-open range operator (..<).
let underFive = 0.0..<5.0
You can use a Range instance to quickly check if a value is contained in a particular range of values. For example:
print(underFive.contains(3.14)) // Prints "true"
print(underFive.contains(6.28)) // Prints "false"
print(underFive.contains(5.0)) // Prints "false"
Range instances can represent an empty interval, unlike ClosedRange.
let empty = 0.0..<0.0
print(empty.contains(0.0)) // Prints "false"
print(empty.isEmpty) // Prints "true"