Operator: ..<

operator ..< { associativity precedence }

Declarations

func ..< <Bound : Comparable>(_: Bound, maximum: Bound)

Returns a half-open range that contains its lower bound but not its upper bound.

Use the half-open range operator (..<) to create a range of any type that conforms to the Comparable protocol. This example creates a Range<Double> from zero up to, but not including, 5.0.

let lessThanFive = 0.0..<5.0
print(lessThanFive.contains(3.14))  // Prints "true"
print(lessThanFive.contains(5.0))   // Prints "false"

Parameters: minimum: The lower bound for the range. maximum: The upper bound for the range.

Declaration

func ..<<Bound : Comparable>(minimum: Bound, maximum: Bound) -> Range<Bound>
func ..< <Bound where Bound : _Strideable & Comparable, Bound.Stride : Integer>(_: Bound, maximum: Bound)

Returns a countable half-open range that contains its lower bound but not its upper bound.

Use the half-open range operator (..<) to create a range of any type that conforms to the Strideable protocol with an associated integer Stride type, such as any of the standard library's integer types. This example creates a CountableRange<Int> from zero up to, but not including, 5.

let upToFive = 0..<5
print(upToFive.contains(3))         // Prints "true"
print(upToFive.contains(5))         // Prints "false"

You can use sequence or collection methods on the upToFive countable range.

print(upToFive.count)               // Prints "5"
print(upToFive.last)                // Prints "4"

Parameters: minimum: The lower bound for the range. maximum: The upper bound for the range.

Declaration

func ..<<Bound where Bound : _Strideable & Comparable, Bound.Stride : Integer>(minimum: Bound, maximum: Bound) -> CountableRange<Bound>