for ... else ?
apatheticagnostic at gmail.com
Tue Jun 12 13:22:54 CEST 2007
On 6/12/07, Nis Jørgensen <nis at superlativ.dk> wrote:
> 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).
I think finally would be semantically nicer than else. . . maybe
something like "andthen" instead (yeah that's ugly).
I mean, else works (so would herbivore), but the terminology is a bit weird.
More information about the Python-list