From the course: iOS Development Tips

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

Ranges

Ranges

- [Instructor] You've probably used ranges and loops, but have you ever thought about their other powers? This time, I'll show you a few things you might want to know about Swift ranges. I put together a playground into a project for an exercise file, which you can find in the downloads. So you can see here, our classic example of a range is a four loop, like this one. I can go ahead and run this, and it just goes through the numbers zero through five. And this is what's known as a closed range, it goes from a beginning number of zero to an end number of five, and uses the operator "dot dot dot." Another thing that you've probably used before is the half open range. Which is what I've got here. So again, it's number in, and then the range is over here, and for this range I've got a zero and this time instead of dot dot dot, I have dot dot less than. And what that means, it'll be one less than the end operator. So in this case, it's actually zero to four. And if you run that, you'll…

Contents