taylor swift taylor swift - 3 months ago 26
Swift Question

How to determine if Swift loop was interrupted

In python we can use

for a in A:

and have the
statement execute if the loop finished normally. Is there a similar construct in Swift?


Such a feature was discussed on the Swift Evolution mailing list and – as far as I can see – rejected. See

which also shows a possible workaround:

outer: do {
    for i in 0..<10 {
        if i == 5 { break outer }
    print("no break occurred")