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

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!

please help again i really don't know what i'm doing wrong!

breaks.py
def loopy(items):
    for b in items:
        print (b)
    if b == "STOP" :
        break

2 Answers

Keir Clyne
Keir Clyne
2,223 Points

Think I've found your problem. They want you to stop printing at the "STOP" but without printing "STOP" itself. So you should put the print function after the break function as shown bellow:

def loopy(items):
    for b in items:
        if b == "STOP":
            break
        print(b)
Keir Clyne
Keir Clyne
2,223 Points

When you are writing for loops make sure you are taking notice of the indentation.

So when you write the code it should look like this:

for something in something_else:
    if thing in something_else:
        print(thing)
        break

A good rule of thumb is that normally after you've given an instruction with a colon at the end you go to a new line and then indent.

Hope this helps!

I tried it but it didn't work or I did someothing wrong. I wrote this: def loopy(items): for b in items: if b == "STOP" : print(items)
break