[Tutor] Strange "snippets" in Learning Python, 2nd ed.

Dick Moores rdm at rcblue.com
Sat Aug 20 18:14:13 CEST 2005


I have the first printing. The snippets are on pp. 159 and 160, and are 
there to illustrate the loop "else" clause.

found = 0
while x and not found:
     if match(x[0]):              # value at front?
         print 'Ni'
         found = 1
     else:
         x = x[1:]                # slice off front and repeat
if not found:
     print 'not found'


while x:                         # exit when x empty
     if match(x[0]):
         print 'Ni'
         break                    # exit, go around else
     x = x[1:]
else:
     print 'Not found'            # only here is exhausted x

"match()" seems to come out of the blue, and also "Ni". Or have I 
misunderstood something?

Thanks,

Dick Moores
rdm at rcblue.com




More information about the Tutor mailing list