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

FHATUWANI Dondry MUVHANGO
FHATUWANI Dondry MUVHANGO
17,796 Points

i need help

i think i'm missing something.... here's my code

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

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

4 Answers

Benjamin Lange
Benjamin Lange
16,178 Points

Before you print the item out, you want to first check if the item is "STOP". You need to put the if statement at the top of the for loop.

FHATUWANI Dondry MUVHANGO
FHATUWANI Dondry MUVHANGO
17,796 Points

ok i tried doing what you said, there is still something wrong

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

Benjamin Lange
Benjamin Lange
16,178 Points

You want the if statement to be inside of the for loop but before the print(item).

FHATUWANI Dondry MUVHANGO
FHATUWANI Dondry MUVHANGO
17,796 Points

Ok I've been trying and using your idea Benjamin, but its not working. And I feel that there is something small that I'm missing

Benjamin Lange
Benjamin Lange
16,178 Points

Here's what you want to do:

Start the for loop like you've already done. The first line of code under the for loop needs to be your if item == "STOP". Make sure that you're checking item and not items. If it is, break, otherwise print item.