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

Alexander Le
Alexander Le
3,735 Points

How do i stop a list mid print, or rather how to i stop a list from printing after hitting a keyword such as 'stop'?

I'm having a difficulty finding the answer to this problem if some one could enlighten me on how to solve this it would be helpful.

breaks.py
def loopy(items):
    # Code goes here
    for words in items:
        if word = "STOP":
        else:
        print(items)

1 Answer

Nicholas Ward
Nicholas Ward
5,797 Points

I'm not 100% sure if this answers your question, but if you put a break statement after your if, nothing else will get printed after the word "STOP". If you use continue instead, the for loop will continue, but the word "STOP" will not get printed.

Also, you might be trying to do something else besides what I'm seeing here, but I think you need to change your for loop to for word in items so you can then use word instead of words in your if statement.