[Tutor] Why is this not an error?

Sean Perry shaleh at speakeasy.net
Sun Mar 20 17:55:55 CET 2005


Hameed U. Khan wrote:
> 
> This else is the part of the for loop. And the statements in this else will be 
> executed if your for loop will complete all of its iterations. if you want 
> this else with 'if' statement then remove the for loop.
> 

for instance:

looking_for = 11

for i in range(0,10):
     if i == looking_for:
         handle_it(i)
         break
else:
     print "Did not find", looking_for


More information about the Tutor mailing list