Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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.