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

Taras Zakharko taras.zakharko at googlemail.com
Thu Mar 31 03:11:03 CDT 2016

> On 30 Mar 2016, at 22:05, Ted F.A. van Gaalen via swift-evolution <swift-evolution at swift.org> wrote:
> Again I need to emphasize very strongly that this for-loop really 
> has absolutely 
>      nothing, nada, zilch, niente, nichts, niets, niks, rien, zero, nenio,
> to do with the: 
> for i in stride(…. 
> or any other for in… variant working with collections.

Of course it does. Collection-based for loop can express exactly the same semantics, so why do you need a new construct when you already have a perfectly good one to do the job? 

> but, once again - 
> provided you don’t want to do other operations
> on the generated collection before iterating -  
> a collection is used here totally unnecessary, 
> which puts a burden on performance because the contents 
> of a collection are unpredictable 

I find it quite irritating that you keep repeating these untrue facts. Again: both for loops compile to exactly the same code. 

> It is also tedious to write and (as a matter of my personal taste) downright ugly.

Right, because 

 for d in stride(from:10, to: 5, by: 0-.1, tolerance: 0.01) 

is that much more tedious to write than what you propose



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160331/28591ecf/attachment.html>

More information about the swift-evolution mailing list