[swift-evolution] C-style For Loops

Tyler Cloutier cloutiertyler at aol.com
Sat Dec 5 12:51:21 CST 2015


Yeah I just threw that syntax together after a few minutes, but if there's actual interesting in consolidating whiles and C style fors, perhaps it warrants further consideration? If list comprehensions are ever to be added, it might be a good idea to allow it to be compatible with the possibility that fors could be used as a generator expression. I know others are talking about a similar thing for if and switch.

Tyler

> On Dec 5, 2015, at 9:28 AM, Roland King <rols at rols.org> wrote:
> 
> 
>> On 5 Dec 2015, at 19:35, Thorsten Seitz <thorsten.seitz at web.de> wrote:
>> 
>> I’m not a big fan of the C-style for loop, mostly because i find the parts of it badly separated by those tiny semicolons which are easily overlooked.
>> 
>> Therefore for me it would be ok if the C-style for loop would be dropped but transforming its syntax into more Swift like syntax like suggested by Tyler might be even better as Roland and Tyler made some good points about advantages of the for loop (especially the guaranteed execution of the increment part). Being able to have the loop variable scoped locally to the loop is another advantage over the while loop.
> 
> I’d be perfectly happy if a semantic equivalent, but syntactically more easily comprehensible, alternative to the c-style for loop was introduced. An extension to while sounds reasonable if there’s a version which is generally agreed to be clearer. I’d like not to throw away what the fullness of what a c-style for loop can express, I don’t mind at all if we throw away the semicolons currently used to express it and replace them with an alternative and more readable syntax. I thought Thorsten’s suggestion for one was fine, I’m sure there are others. 
> 


More information about the swift-evolution mailing list