Break and Continue

The break statement

  • Exits the enclosing loop
     while 1:
         cmd = raw_input("Enter command > ")
         if not cmd: break
         # Process command
         ...

The continue statement

  • Returns to the top of the loop (skips the rest of the loop body)
     # Print non-negative list elements
     for item in s:
         if item < 0: continue
         print item 
<<< O'Reilly OSCON 2000, Introduction to Python, Slide 65
July 17, 2000, beazley@cs.uchicago.edu
>>>