what is Closed Range Operator in Swift?

0 votes
52 views
asked Feb 24, 2015 in Swift by jonathan (3,105 points)
Hi All

   what is Closed Range Operator in Swift?

1 Answer

0 votes
answered Feb 24, 2015 by john (4,220 points)

The closed range operator (a...b) defines a range that runs from a to b, and includes the values a and b. The value of a must not be greater than b.

The closed range operator is useful when iterating over a range in which you want all of the values to be used, such as with a for-in loop:

   for index in 1...5 {

    println("\(index) times 5 is \(index * 5)")

 }

Half-Open Range Operator

The half-open range operator (a..<b) defines a range that runs from a to b, but does not include b. It is said to be half-open because it contains its first value, but not its final value. As with the closed range operator, the value of a must not be greater than b.

...