Swift BasicsLesson 14Free preview
Swift Ranges
This lesson is part of Swift · All levels
Summary
This lesson is a peek at the Range Operators in Swift that are used to express sequential range values. Swift provides an inclusive closed range operator and a half-open range operator that excludes the end limits. This range is very commonly used in for-repetition and slicing collections. (.b)
Key points
- Closed Range Operator 'a...b' includes all values from a to b (included)
- Half-Open Range Operator 'a..<b' includes a value from a to less than b (excluding the end limit)
- One-Sided Ranges (such as 'a...' or '...b') are used to take slices of a collection to the ends
- Supports the verification of membership value using the '.contains(value) method
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.