Range 정의
예제
let underFive = 0.0..<5.0
underFive.contains(3.14)
// true
underFive.contains(6.28)
// false
underFive.contains(5.0)
// false
let empty = 0.0..<0.0
empty.contains(0.0)
// false
empty.isEmpty
// true
for n in 3..<5 {
print(n)
}
// Prints "3"
// Prints "4"
ClosedRange 정의
예제
let throughFive = 0...5
throughFive.contains(3)
// true
throughFive.contains(10)
// false
throughFive.contains(5)
// true
let zeroInclusive = 0...0
zeroInclusive.contains(0)
// true
zeroInclusive.isEmpty
// false
for n in 3...5 {
print(n)
}
// Prints "3"
// Prints "4"
// Prints "5"