'while/else' (ugh) (was Re: [oclug] Ruby)
Rod Giffin
rod at giffinscientific.com
Fri Jun 27 13:05:38 EDT 2003
David F. Skoll said:
> On Fri, 27 Jun 2003, Rod Giffin wrote:
>
>> > while not found:
>> > line = fp.readline()
>> > if not line: break
>> > if re.search(pattern, line):
>> > found = True
>> > else:
>> > print "we didn't find the pattern"
>
> Am I the only one who finds that repugnant?
>
> When, exactly, does the "else" fire? If the loop is iterated zero
> times? If the loop is ever exited with "found" still false?
The else would not fire, unless "found" was true when you attempted to
enter the loop.
Rod.
More information about the OCLUG
mailing list