[swift-evolution] A (better) Swift Equivalent For The Classical For-Loop With Numeric Scalars

Brent Royal-Gordon brent at architechies.com
Wed Mar 23 22:59:47 CDT 2016


> I get this
> 
> var i:Int = 0
> for i in (0..<len)
> {
>     //do something
> }
> 
> ....
> 
> for i in (0..<len)
> {
>     if something is true
>     {
>         break
>     }
> }
> 
> use i ??
> What is i now :)  !!!!

The outer `i` is 0 because it was never used. The expression `for i in...` implicitly declares a new `i`.

-- 
Brent Royal-Gordon
Architechies



More information about the swift-evolution mailing list