[swift-evolution] repeat loop enhancement

Brent Royal-Gordon brent at architechies.com
Wed Dec 9 15:26:02 CST 2015

> Likely because 
> for 1…5 {
> }
> is the same as 
> for 2…6 or for 0…4 
> which is confusing.

Sure, but the same is true of `for _ in 1…5`. The way I see it, this allows you to start by introducing “here’s how you do something five times”:

	for 1…5 {

And then extend the very same syntax to “here’s how you find out which time you’re on”:

	for i in 1…5 {
		print(“Hello \(i)!”)

And from there, you can talk about how `1…5` can have different starting and ending points, can be a list of values instead of a series of numbers, etc. Seems like a nice way to make sure that learners *start* by using the same construct they’ll *finish* with.

Brent Royal-Gordon

More information about the swift-evolution mailing list