D
Diez B. Roggisch
Hi,
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?
I imagined that the else-clause would only be executed if the loop body
wasn't entered, so I could write this
for r in result:
print r
else:
print "Nothing found, dude!"
instead of
if len(result):
for r in result
print r
else:
print "Nothing found, dude!"
waiting for enlightment,
Diez
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?
I imagined that the else-clause would only be executed if the loop body
wasn't entered, so I could write this
for r in result:
print r
else:
print "Nothing found, dude!"
instead of
if len(result):
for r in result
print r
else:
print "Nothing found, dude!"
waiting for enlightment,
Diez