[swift-evolution] Change 'for in' expression to for [] { (item) in ... }

Daryle Walker darylew at mac.com
Sat Jul 29 18:01:55 CDT 2017


> On Jul 28, 2017, at 12:19 PM, Kwanghoon Choi via swift-evolution <swift-evolution at swift.org> wrote:
> 
> Hello
> 
> I found someone easy mistake using for in loop statement.
> 
> Ex)
> var i = 0
> for i in 0..<10 { }
> print(i)
> 
> And this user expected print(i) is “10”
> 
> Many experienced swift developers doesn’t misunderstand like this. But always someone is new comers, and I think this expression make misunderstand easy too.
> 
> So why not like this?
> 
> var I = 0
> for 0..<10 { (i) in … }
> 
> I think this is more understandable for loop expression. 

Maybe a better change would be for every function not nested within another, all local variables (including the in-function name for parameters and the parameters/locals of nested functions) need to be uniquely named. (I think some obscure language I read about once does this.)

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT com 



More information about the swift-evolution mailing list