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

Kennedi Armstrong
Kennedi Armstrong
883 Points

Not sure what is wrong here

Oops, I forgot that I need to break out of the loop when the current item is the string "STOP". Help me add that code!

def loopy(items):
    # Code goes here
    for thing in items:
    if thing == "STOP":

1 Answer

28,558 Points

Python groups code based on how they are indented (spaced). By placing your if statement on the same level as the for loop it is considered to be outside of it, and as such it won't run until after the loop has finished.

You therefore need to indent the code so that the if statement is within the loop just like your print statement is currently. It's also worth noting that the challenge wants the if statement to be above the print statement. That is something the instructions are not super clear about but is one of the requirements to complete the challenge.