break and continue, online

Six activities your students do on their own devices. See who's finished, and their scores.

break and continue in one minute

What students need to know

break exits the loop immediately when the condition is met. continue skips printing when i==2 but the loop continues for other values.

continue skips the rest of this iteration and jumps to the next one. break only makes sense inside a loop — Python raises SyntaxError otherwise.

Mistakes students make

  • break must be INSIDE a loop: it can't be used outside.
  • break must be lowercase Break is not valid Python.
  • continue must be lowercase Continue is not valid Python.
  • break must be indented inside the if block.

Discover other journeys with this module

What students will learn in this module

Every question in Module 23

Quick questions

  1. What does break do?ASkips to next iterationBExits the loop immediately
  2. What does continue do?ASkips to the next iterationBExits the loop
  3. for i in range(5):\n if i == 3:\n break\n print(i)\nWhat prints?A0, 1, 2, 3B0, 1, 2
  4. for i in range(5):\n if i == 3:\n continue\n print(i)\nWhat prints?A0, 1, 2, 4B0, 1, 2
  5. Can you use break outside a loop?ANo causes SyntaxErrorBYes

Key terms

Students type the meaning of:

  • break
  • continue
  • while True: + break
  • Loop control

Match the pairs

breakMatch it to what it does
for i in range(5):
    continue
    print(i)
Match it to what it does
for i in range(5):
    if i == 3:
        break
Match it to what it does
for i in range(5):
    if i == 2:
        continue
    print(i)
Match it to what it does
for i in range(5):
    if i == 3:
        break
    print(i)
Match it to what it does
for i in range(4):
    if i == 2:
        continue
    print(i)
Match it to what it does

Fill in the blanks

  1. for i in range(10):
        if i == 5:
            _____
        print(i)
  2. for i in range(10):
        if i == 3:
            ________
        print(i)
  3. while True:
        x = input('Enter: ')
        if x == 'quit':
            _____
  4. for i in range(10):
        if i % 2 __ 0:
            continue
        print(i)
  5. for i in range(20):
        if i __ 10:
            break
        print(i)

Spot the error

Question 1

AbreakBfor i in range(5):C    print(i)Dprint('Done')

Question 2

Afor i in range(10):B    if i == 5:C        BreakD    print(i)

Question 3

Afor i in range(10):B    if i == 5:C        ContinueD    print(i)

Question 4

Afor i in range(10):B    if i == 5:C    breakD    print(i)

Question 5

Afor i in range(10):B    if i == 5:C        break()D    print(i)