[swift-evolution] Hidden initiallizations ...

Brent Royal-Gordon brent at architechies.com
Mon Mar 28 20:16:48 CDT 2016


> What is the value of i ??

0, because `for i` implicitly declares a new variable `i`. You could perhaps argue that you should have to explicitly say `for let i`, but that seems pointless because the `let` would always be necessary. (Well, unless you did a `for case` or `for _`, but those are rare constructs.)

> My suggestion is to use the variable i in the loop instead of making hidden init of another "i" for the loop. 

That seems like an extremely bad idea. What if the loop variable is a property or global and you accidentally end up using it implicitly? That's *way* worse than shadowing the outer variable.

-- 
Brent Royal-Gordon
Architechies



More information about the swift-evolution mailing list