for ... else ?
Nis Jørgensen
nis at superlativ.dk
Tue Jun 12 06:12:41 EDT 2007
exhuma.twn skrev:
>> for number in range(10,100):
>> for divisor in range(2,number):
>> if number % divisor == 0:
>> break
>> else:
>> print number,
>>
>
> Oh my. Would it not be an idea to rename this "else" into a "finally"?
> As Gabriel points out, the else-block gets executed after the for loop
> exits *normally*. In that case, is the "else" not semantically
> misleading? I would surely misunderstand it if I saw it the first time.
"finally" would be at least equally confusing IMO, indicating that the
code is always called (although this would of course make it a
ridiculous construct).
/Nis
More information about the Python-list
mailing list