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

Greg Isaacson
PLUS
Greg Isaacson
Courses Plus Student 702 Points

Please help:)

Hi all...

Not sure what I am doing wrong.

I want to make a condition that if items == "STOP" then it breaks??

Thanks

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

2 Answers

Stuart Wright
Stuart Wright
41,120 Points

Note that in your code 'items' refers to the entire list, and 'item' refers to the current item as you iterate through the list.

You are asked to print the current item and break if the current item is equal to 'STOP', but currently you are printing the entire list, and breaking if the entire list is equal to 'STOP', which will never be the case.

Greg Isaacson
Greg Isaacson
Courses Plus Student 702 Points

Hi Stuart,

I changed my code to this:

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

It is still failing?

Stuart Wright
Stuart Wright
41,120 Points

Hi Greg - I think the exercise might want you to put the condition before the print statement, so check to see if item = 'STOP' first, break if so, and if not print the item.