Currently, for-loops admit a "where" clause:

    for x in seq *where* cond {
        ...
    }

    behaves like

    for x in seq {
        if !cond { continue }
        ...
    }


I'd be interested in a "while" clause:

    for x in seq *while* cond {
        ...
    }

    would behave like

    for x in seq {
        if !cond { break }
        ...
    }


This is one area where C-style for-loops would have provided a clean
solution (combining multiple conditions with &&), but once they're removed
any extra conditions will have to move inside the loop.

Pros:
- It's a simple way to express a common piece of control flow that
otherwise requires negation and another set of braces.
- Its meaning is easy to understand.

Cons:
- It's a new feature.
- Naming might cause confusion with while-loops.

Open questions:
- How/could it be combined with "where" clauses? Would order matter?
- Does anyone else care?


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

Reply via email to