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

chiu szu ting
chiu szu ting
2,318 Points

Didn't find the right items being printed

don't know where did the error happened

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

1 Answer

Peter Lawless
Peter Lawless
24,404 Points

The way your function is written now, it won't print anything because the only print statement is preceded by 'break' which will stop the execution of the function without reading another line of code. I think what you want is to add an 'else' clause that will allow the item to be printed. The logic is like this: if the item in the list is "STOP", then break out of the function, else print the item. In code, it should look like this:

def loopy(items):
    # Code goes here
    for item in items:
        if item == "STOP":
            break
        else:
            print(item)
chiu szu ting
chiu szu ting
2,318 Points

this really helps!! though i'm new in programming,i knew exactly what you're saying. thank you! :)