Imagine you need to write a program for a department store. This program will automatically send a discount voucher to customers between the ages of 18 and 30. It would be very cumbersome if you needed to set up an if or switch statement for each age. It's much more convenient if there was a way to specify a range of numbers, and that is what a range operator does.
For more information on range operators, visit: https://docs.swift.org/swift-book/LanguageGuide/BasicOperators.html.
Let's say you want to represent a sequence of numbers from 10 to 20. You don't need to specify every value; you can just specify the first number and the last number in this way:
firstNumber...lastNumber
Let's try this out in the playground. Do the following steps.
- Type the following into the playground and run it:
// closed range operator
let myRange = 10...20
This...