Junior Codes
Clockwork Woods

Searching a List and Using break in Python for Kids

Look through items one by one and stop as soon as you find it.

Start Wonderwild free with Pip

Try 5 starter activities free. Full access is ₹499 a year.

This mission is part of full access. The first missions are free to try.

Searching & break, explained simply

If you are looking for your shoes, you stop searching once you find them. A loop can do the same thing with break.

break ends the loop immediately, even if there are items left. The program then carries on with the first line after the loop.

A common pattern is to loop through a list, check each item with if, and break when you find a match. You can use a variable to remember whether you found anything at all.

Example: Find the compass

places = ["tent", "river", "cave", "hill"]
for place in places:
    print("Checking the", place)
    if place == "cave":
        print("Found the compass!")
        break

Output

Checking the tent
Checking the river
Checking the cave
Found the compass!

The hill is never checked because break stopped the loop.

Try this

  • Remove break and see how the output changes.
  • Search for something that is not in the list and print "Not found" at the end.
  • Use break inside a while True loop to stop when the player types "quit".

Practise it in Wonderwild

“Find the lost compass”

Mission 17 in Clockwork Woods, one of 36 Python missions in Wonderwild.

Your child writes and runs real Python in the browser while Pip reacts to every line. Nothing to install. For ages 7+.

Start Wonderwild free with Pip

Try 5 starter activities free. Full access is ₹499 a year.

This mission is part of full access. The first missions are free to try.

Questions parents and kids ask

Is break bad practice?+

No. Used for an early exit from a search or a menu loop, break makes code shorter and clearer.

Does break stop the whole program?+

No, only the loop it is inside. The rest of the program keeps running.

Prefer learning with a teacher?

Our live Python for Young Developers course teaches these ideas in small online classes led by a software engineer, with projects and feedback. Every live course also includes 12 months of full Wonderwild access for practice.

See the Python for Young Developers course