for what are for/while else clauses

Rene Pijlman reply.in.the.newsgroup at my.address.is.invalid
Fri Nov 14 14:53:17 EST 2003


Diez B. Roggisch:
>today I rummaged through the language spec to see whats in the for ... else:
>for me. I was sort of disappointed to learn that the else clauses simply
>gets executed after the loop-body - regardless of the loop beeing entered
>or not.
>
>So where is an actual use case for that feature? 

To execute code only when the loop terminates normally, not when it
terminates because of a break statement.

It's been discussed before:
http://groups.google.nl/groups?q=%2Bfor+else+group:comp.lang.python&hl=nl&lr=&ie=UTF-8&oe=UTF-8&selm=slrn9teq1k.1vd.huaiyu%40gauss.almadan.ibm.com&rnum=3
http://groups.google.nl/groups?q=%2Bfor+else+group:comp.lang.python+break&hl=nl&lr=&ie=UTF-8&oe=UTF-8&selm=uofzrqjex.fsf%40ctwd0143.fitlinxx.com&rnum=7
http://groups.google.nl/groups?hl=nl&lr=&ie=UTF-8&oe=UTF-8&threadm=uofzrqjex.fsf%40ctwd0143.fitlinxx.com&rnum=7&prev=/groups%3Fq%3D%252Bfor%2Belse%2Bgroup:comp.lang.python%2Bbreak%26hl%3Dnl%26lr%3D%26ie%3DUTF-8%26oe%3DUTF-8%26selm%3Duofzrqjex.fsf%2540ctwd0143.fitlinxx.com%26rnum%3D7

-- 
René Pijlman




More information about the Python-list mailing list