Python Break & Continue Statement Exercises

Let’s check out some exercises that will help understand Break and Continue statements better.

Exercise 10-a: Break statement inside a For Loop

Place a break statement in the for loop so that it prints from 0 to 7 only (including 7).

When the line with break statement is executed program exits that loop.

for i in range(100):
if i == 7:

Exercise 10-b: If and Continue statements inside a For Loop

Add an if statement and a continue statement to the loop so that it skips when iterator equals "sun".

When the line with continue statement is executed program skips that iteration and goes back to where it left in the loop.

for i in weather:
if i == "sun":