Chapter    17

Range Operators

You use range operators to specify a range of integers such as 1 through 10. There are two types of range operators: the closed range operator (...) and the half-open range operator (..<).

Closed Range Operator

The closed range operator gives you a way to specify a range of numbers when you want to include the number that defines the end of the range. You must specify the beginning of the range and the end of the range with the closed range operator (...), as shown in Listing 17-1.

Listing 17-1. Closed Range Operator

1...10

This operator is not useful by itself, but you will see range operators used in for loops (see Chapter 22), as shown in Listing 17-2.

Listing 17-2. Closed Range Operator in a for Loop

for i in ...

Get Swift Quick Syntax Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.