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

Dmitri Gribenko gribozavr at gmail.com
Sat Mar 19 02:46:33 CDT 2016


Hi Ted,

Thank you for starting this thread.  I agree that removing the C-style
for loop has degraded the readability and clarity of some of numerics
code.

In the feedback to SE-0007 many people have said that they can convert
their code to for-in loops, but I think this actually means that in
code that is typically written in Swift today, loops primarily operate
on sequences and collections.  It means that numerics is a domain that
not many people work in.  But it is a very important domain
nevertheless, and clarity for numerics code matters at least as much
as it does everywhere else.

I think one way to approach this discussion would be to present
multiple concrete code samples that contain C-style for loops and are
awkward to write without them.  We can then try looking for patterns,
generalize and simplify, and discuss possible solutions.

Dmitri

-- 
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/


More information about the swift-evolution mailing list