Skip to content

Instantly share code, notes, and snippets.

@jjfajardo
Created November 26, 2013 23:15
Show Gist options
  • Save jjfajardo/7668013 to your computer and use it in GitHub Desktop.
Save jjfajardo/7668013 to your computer and use it in GitHub Desktop.
how to break nested for loops
#!/usr/bin/env python
#Example written by jfajardo. 2013
# This trivial program shows how to break to nested for loops, when a
# condition is TRUE
for letter in 'murcielago':
for i in range(10):
if(letter == "c" and i == 2):
break
print letter, i
else:
continue # executed if the loop ended normally (no break)
break # executed if 'continue' was skipped (break)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment