[swift-evolution] Revisiting 0004 etc. - Swift deprecations

David Owens II david at owensd.io
Sat Apr 2 23:54:07 CDT 2016


The C99 spec changed the scoping rules to address the very issue you are asking about having any "real-world impact".

Yes, the variable outside does matter. It's why you see some code like this, even with C++ because it used to not scope locally there too with all compilers:

{for (int i= 0; i<10; i++) { ... }}

And as fully explained in the previous threads on the topic, the defer pattern is an insufficient mechanism to generically be used for all c-style for loop constructs. 

-David

Sent from my iPad

> On Apr 2, 2016, at 7:35 PM, David Sweeris via swift-evolution <swift-evolution at swift.org> wrote:
> 
> 
>> On Apr 2, 2016, at 20:49, Charles Srstka via swift-evolution <swift-evolution at swift.org> wrote:
>> 
>> While this style works, and definitely can substitute for a classical for loop, it is not quite as nice, because it cannot limit i’s scope to the loop. The variable will be visible outside of the loop body.
> 
> I agree it's not as nice aesthetically, but does the loop variable being visible outside the loop cause any real-world problems?
> 
> - Dave Sweeris
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution


More information about the swift-evolution mailing list