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.

Clayton McDaniels
5,776 PointsWhy is the code below not working for this challenge?
def loopy(items): for thing in items: print(thing) if items == 'STOP': break
def loopy(items):
for thing in items:
print(thing)
if items == 'STOP':
break
2 Answers

Steve Hunter
57,682 PointsHi Clayton,
If the user enters STOP, don't print but just break
. So, put your if
before the print
line.
Also, you want to see if thing
equals STOP, not items
.
Steve.

Clayton McDaniels
5,776 PointsSteve, your followup reply makes more sense and is more logical. I thought that should work too, however the challenge accepted just moving the if statement.

Steve Hunter
57,682 PointsYou got lucky, I reckon. I tried it with just moving the statement and it failed. Still, it doesn't matter! Enjoy the rest of the course!
Clayton McDaniels
5,776 PointsClayton McDaniels
5,776 PointsCopying the if before the print line worked! All else is fine! Thank you!
Steve Hunter
57,682 PointsSteve Hunter
57,682 PointsI found that just moving the
if
wasn't sufficient. This doesn't work:Whereas changing
if items == "STOP":
toif thing == "STOP":
meant that the code is comparing the for loop variable which holds each element ofitems
in turn, which isthing
. This code worked:Steve.