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

Paul Webb
seal-mask
.a{fill-rule:evenodd;}techdegree
Paul Webb
Front End Web Development Techdegree Student 453 Points

i need help with getting the script to break if "STOP" is found in (items)?

thanks

breaks.py
def loopy(items):
    for x in (items):
        print(items)        #this prints all the variables in (items)
    else "STOP" in (items):        #not sure the the right way to code this part
        break
Brian DuPont
Brian DuPont
30,448 Points

Alright, so we are passing in a items array into the loopy function. Then the for loop, loops over each variable in the items array and puts the current value into 'x'. So INSIDE of the for loop we need to check for "STOP", using an if statement. If x == STOP then break, else print x (which is the current item in the items array). Hope this helps.

def loopy(items) :
    for x in (items) :
        if x == "STOP" :
            break
        else :
            print(x)

1 Answer