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

Eric Marangu
seal-mask
.a{fill-rule:evenodd;}techdegree
Eric Marangu
Python Web Development Techdegree Student 730 Points

for loop break statement now working

I have written the code attached but can't get what's wrong with it. Please help

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

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! First, you're doing great, but let's translate your code to English and see what it says:

For every individual item in the items list:
   print the entire items list
If the individual item is STOP:
   stop the loop

This means that every time you get to a new item, you don't print the item but rather the entire list. Above and beyond that, you will also be printing out "STOP". Let's imagine that your list contains ["bread", "butter", "cheese", "STOP"]. You should first check to see if it is stop and if it is, break from the loop. Otherwise, it will print out stop and then break.

I think you can get it with these hints, but let me know if you're still stuck! :sparkles: