break and continue Statements, and Else Clauses on Loops : break « Statement « Python Tutorial






for n in range(2, 10):
   for x in range(2, n):
       if n % x == 0:
           print n, 'equals', x, '*', n/x
           break
   else:
       print n, 'is a prime number'








3.5.break
3.5.1.Breaking Out of Loops
3.5.2.break out of a while loop
3.5.3.Use break to stop execution and break out of the current loop
3.5.4.break and continue Statements, and Else Clauses on Loops