Using the break statement in a for structure. : Break « Language Basics « Python






Using the break statement in a for structure.

Using the break statement in a for structure.


for x in range( 1, 11 ):

   if x == 5:
      break

   print x,

print "\nBroke out of loop at x =", x


           
       








Related examples in the same category

1.Using the break statement to avoid repeating code in the class-average program.Using the break statement to avoid repeating code in the class-average program.
2.Break and continue Statements, and else Clauses on LoopsBreak and continue Statements, and else Clauses on Loops
3.While with breakWhile with break