Larry Hudson wrote:
On 06/08/2011 01:09 PM, Cathy James wrote:
Dog Breed: "))
     while not dogs:
         print("Goodbye!!")
         sys.exit()
     else:

else does not belong with while.

else works just fine with while; it is the path taken when the while is exhausted, but not broken out of:

--> i = 5
--> while i:
...   print(i)
...   i -= 1
... else:
...   print("blast off!")
...
5
4
3
2
1
blast off!


--> i = 5
--> while i:
...   print(i)
...   i -= 1
...   if i == 3:
...     print('aborting')
...     break
... else:
...   print("blast off!")
...
5
4
aborting

~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to