[swift-evolution] else clause for loops like that in Python
Jordan Rose
jordan_rose at apple.com
Tue Dec 8 18:13:21 CST 2015
> On Dec 8, 2015, at 14:50, Brent Royal-Gordon via swift-evolution <swift-evolution at swift.org> wrote:
>
>> But to avoid confusion, maybe rename “else” to “nobreak”:
>>
>> for i in 0..<10 {
>> if i == 5 { break }
>> } nobreak {
>> // no break occurred
>> }
>
> I’ve often wanted an else clause on loops—but one that would run only if the loop went through zero iterations. I can’t imagine when I would ever use `nobreak`.
Yep, this is the one I'd want. But I think we probably just shouldn't have either, especially now that we've seen that there are two possible interpretations. Amir, a workaround for yours today:
outer: do {
for i in 0..<10 {
if i == 5 { break outer }
}
print("no break occurred")
}
Jordan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151208/ae61e2b8/attachment.html>
More information about the swift-evolution
mailing list