Break and continue Statements, and else Clauses on Loops : Break « Language Basics « Python






Break and continue Statements, and else Clauses on Loops

Break and continue Statements, and else Clauses on Loops

for n in range(2, 10):
     for x in range(2, n):
         if n % x == 0:
             print n, 'equals', x, '*', n/x
             break
     else:
         # loop fell through without finding a factor
         print n, 'is a prime number'


           
       








Related examples in the same category

1.Using the break statement in a for structure.Using the break statement in a for structure.
2.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.
3.While with breakWhile with break