[swift-evolution] Review for: Remove C-style for-loops with conditions and incrementers

Kevin Ballard kevin at sb.org
Mon Dec 7 19:29:15 CST 2015

On Mon, Dec 7, 2015, at 01:07 PM, Dmitri Gribenko via swift-evolution
> Another concern of mine is the equivalent of C-style for loops with
> 'continue' statements in them.  The only equivalent based on 'while' I
> can think of duplicates the increment portion of the loop.

As has been pointed out in other threads on this topic, you can use a
defer statement to avoid duplicating the increment portion:

var i = initial
while cond(i) {
    defer { i = increment(i) }
    // ...
    if frob {
        continue // defer will execute


More information about the swift-evolution mailing list