[swift-evolution] Change `repeat` to loop indefinitely if no while clause is present

Nicholas Maccharoli nmaccharoli at gmail.com
Tue May 10 02:27:03 CDT 2016

​Swift Evolution ​Community,

Currently writing an infinite loop in swift looks either something like

    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

How does it sound?

- Nick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160510/37eefa9c/attachment.html>

More information about the swift-evolution mailing list