Posted By

magicrebirth on 12/22/09


Tagged

iteration break for if continue


Versions (?)

Python: iteration, break and continue


 / Published in: Python
 

The Python language provides break to stop execution and break out of the current loop. Python also includes continue to stop execution of the current iteration and start the next iteration of the current loop. The following example shows the use of the break and continue statements:

  1. >>>word = "Pithon Phrasebook"
  2. >>>string = ""
  3. >>>for ch in word:
  4. >>> if ch == 'i':
  5. >>> string +='y'
  6. >>> continue
  7. >>> if ch == ' ':
  8. >>> break
  9. >>> string += ch
  10. >>>print string
  11. Python

Report this snippet  

You need to login to post a comment.