[swift-evolution] else clause for loops like that in Python

Amir Michail a.michail at me.com
Tue Dec 8 16:07:34 CST 2015


> On Dec 8, 2015, at 4:50 PM, Alex Chan <alex at alexwlchan.net> wrote:
> 
> I’d be inclined not to add this feature.
> 
> My impression is that (in Python) many people have either never come across this feature or find its behaviour confusing. I don’t think it’s a particularly widely used feature, and I don’t think it’s necessary for Swift.
> 
> If we do add it, I strongly agree with changing the name. One of the biggest confusions in Python is the mismatch between if…else and for…else. Renaming it would help.

Maybe it’s not used much in python because the name is confusing? “nobreak” would be better than “else”.

> 
> — Alex
> 
> 
> (For the non-Python programmers on the list: the “else” is an optional branch at the end of for/while loops that runs only if the loop exits cleanly/doesn’t break.)
> 
>> On 8 Dec 2015, at 18:35, Amir Michail 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
>> }
>> 
>> 
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org
>> https://lists.swift.org/mailman/listinfo/swift-evolution
> 



More information about the swift-evolution mailing list