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

Shubham Modi
Shubham Modi
5,799 Points

for loop condition what to put

I need you to help me finish my loopy function. Inside of the function, I need a for loop that prints each thing in items. But, if the current thing is the string "STOP", break the loop.

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

For starters you don't need any input from the user- you just loop through checking each item in the iterable that is passed in. Also, before you print you probably need to check to see if the current item in the loop is 'STOP' and if it is then break otherwise you print the item.

I hope this helps.

2 Answers

Özgür Ozan Çakmak
Özgür Ozan Çakmak
11,451 Points

Also you need to put a colon after the if statement and indent the break:

if thing == 'STOP':
   break

I tried this and it works, but I can't passed the challenge.

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