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
Alexander Le3,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.
# Code goes here
for words in items:
if word = "STOP":
Nicholas Ward5,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.