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

Alex Durham
PLUS
Alex Durham
Courses Plus Student 456 Points

break

can someone help me with the break thanks!

breaks.py
def loopy(items):
    for item in items:
        print(item)
    if item == 'STOP':
        break
Steven Parker
Steven Parker
231,269 Points

Remember to mark the question closed (by selecting a "best answer") once you are satisfied with an answer.

2 Answers

james south
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
james south
Front End Web Development Techdegree Graduate 33,271 Points

you are close, your indentation is off, the if block is under the loop not in it, so tab it over. then you will need to break before printing the item so check the string and break if needed, else print the item.

Your if statement is outside the loop. It should be inside the loop!

Try something like this:

def loopy(items):
    for item in items:
        if item == 'STOP':
            break
        else:
            print(item)