[swift-evolution] repeat loop enhancement
Stephen Celis
stephen.celis at gmail.com
Wed Dec 9 09:02:20 CST 2015
On Wed, Dec 9, 2015 at 9:41 AM, Jason Pollack via swift-evolution <
swift-evolution at swift.org> wrote:
> Solutions like this look reasonable, until you try to use normal control
> flow statements as you would in other loops. In the closure, a break or
> continue are illegal, and a return acts like a continue.
>
> var ok = true
>
> 5.times {
> ok = someTest()
>
> if (!ok) {
> //break - Nope!
> return //Sure, but loop continues anyway
> }
> }
>
> Sure, it's a contrived example, but it's easy to see how this construct is
> not like other loops.
>
> On the other hand, it might be nice to be able to decorate a closure such
> that break and continue behave as one might expect inside a loop, but that
> sounds like a can of worms.
>
Joe Groff suggested that here:
https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20151207/001150.html
If you can think of reasons why it might be a can of worms, I'd love to
hear them. It'd be a nice tool to have in the toolchain.
Stephen
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151209/a0182352/attachment.html>
More information about the swift-evolution
mailing list