> On 28 Jul 2017, at 17:19, Kwanghoon Choi via swift-evolution 
> <swift-evolution@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”

The variable shadows any reference in the loop; and in addition, it's a 
constant value.

1> for i in 0..<10 { i+=1 } 
error: repl.swift:7:20: error: left side of mutating operator isn't mutable: 
'i' is a 'let' constant
for i in 0..<10 { i+=1 }
                  ~^

> 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 … }

You can already do this:

2> (0..<10).forEach { i in print(i) } 

Alex
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to