I’d actually say that I’m strongly in favor of allowing just a repeat keyword, 
although I wouldn’t support making 'while true’.

Firstly it reduces clutter and makes it very clear that the the code is just 
supposed to repeat. 
Secondly it’s a very simple way of introducing new programmers to loops. It’s 
IMHO more clear to a new programmer that repeat will just repeat indefinitely 
vs while true.
Lastly, this isn’t the first time this has been brought up on this list and 
there was previously discussion about the fact that when people see the repeat 
keyword that it should naturally repeat indefinitely unless a where clause is 
specified.

I also think the concern that an accidental infinite loop is any greater than 
it is currently.

Tyler



> On May 10, 2016, at 1:09 PM, Erica Sadun via swift-evolution 
> <[email protected]> wrote:
> 
> I do not see sufficiently measurable benefits to this proposal to add it to 
> the language. 
> It's easy enough to roll your own `repeatForever` function with trailing 
> closure.
> 
> I also want to thank you for bring it up on-list. Not every idea is right for 
> Swift but it's
> always refreshing to see innovative thoughts added to the discussion. Please 
> do not be 
> discouraged by the generally negative feedback on this particular idea.
> 
> -- Erica
> 
>> On May 10, 2016, at 1:27 AM, Nicholas Maccharoli via swift-evolution 
>> <[email protected] <mailto:[email protected]>> wrote:
>> 
>> ​Swift Evolution ​Community,
>> 
>> Currently writing an infinite loop in swift looks either something like this:
>> 
>>     while true {
>>         if ... { break }
>>         //...
>>     }
>> 
>> Or this:
>> 
>>     repeat {
>>         if ... { break }
>>         //...
>>     } while true
>> 
>> But I think it might be best to change the syntax / behaviour of `repeat` to 
>> loop 
>> indefinitely if no trailing while clause is present:
>> 
>>     repeat {
>>         if ... { break }
>>         //...
>>     }
>> 
>> while still allowing a trailing `while` clause as in:
>> 
>>     repeat { 
>>         foo += bar
>>     } while foo.count < limit 
>> 
>> I also want to propose that it should be a compile time error to use single 
>> `Bool` constants as while loop conditions, so no more `while true { ... }` 
>> it would become `repeat { ... }`
>> 
>> I was thinking of drafting a short proposal if there was enough positive 
>> feedback. 
>> 
>> How does it sound?
>> 
>> - Nick 
>> _______________________________________________
>> swift-evolution mailing list
>> [email protected] <mailto:[email protected]>
>> https://lists.swift.org/mailman/listinfo/swift-evolution
> 
> _______________________________________________
> swift-evolution mailing list
> [email protected]
> https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to