Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Python Basics (2015) Shopping List App Break

What is wrong?

Struggling to complete this code challenge - not to sure what's going wrong...

breaks.py
def loopy(items):
    # Code goes here
    for name in items:
        print(name)
    if name == "STOP":
        break 

1 Answer

Ari Misha
Ari Misha
19,323 Points

Hiya Matthew! The issue with your code is subtle but its all about logic. See you've placed print(name) before your "if" statement. The "for" loop will execute your print() first , followed by your "if" statement. By the time, it'll get to your "if", their wont be any "STOP" to tackle in items , hence nothing to break out of, ya know what i mean? So yeah place your "if" statement before your print(name) and it'll defo work. (: