[swift-evolution] else clause for loops like that in Python
Amir Michail
a.michail at me.com
Tue Dec 8 17:29:11 CST 2015
> On Dec 8, 2015, at 5:50 PM, Brent Royal-Gordon <brent at architechies.com> 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`.
What about searching for something in an array? The not found code would go in the nobreak clause.
>
> --
> Brent Royal-Gordon
> Architechies
>
More information about the swift-evolution
mailing list