Skip to main content

Range

A half-open range from lower bound up to, but not including, upper bound.

class Range
var range1 = Range(10) // a range from 0 to 9
var range2 = Range(lower: -10, upper: 10) // a range from -10 to 9

Iterating

A range can be iterated using the for loop.

for index in Range(10) {
print("\{index}")
}

Constructors

Zero-Based

constructor(_ upper: Int)

Creates a range from 0 to upper (excluded).


Bounded

constructor(lower: Int, upper: Int)

Creates a range from lower to upper (excluded).

Properties

lower

lower: Int { get }

The lower bound of the range


upper

upper: Int { get }

The upper bound of the range