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 trialConner Williams
Courses Plus Student 3,305 Pointshow do I solve the second half of this challenge?
how do I properly use the break function to end this loop?
def loopy(items):
for item in items:
print (item)
if item == "STOP":
break
4 Answers
Ben Reynolds
35,170 PointsClose, you just need to check for 'STOP' before it prints instead of after.
Ben Reynolds
35,170 PointsCan you share the last version of the code that you've tried?
Conner Williams
Courses Plus Student 3,305 Pointsdef loopy(items): for item in items: new_item = input('> ') if new_item == 'STOP': break print(item)
Ben Reynolds
35,170 Points- Delete the new_item = input line, you don't need an input for this one
- Set the variable names in the "if" and "print" statements back to "item" again
Conner Williams
Courses Plus Student 3,305 PointsGOT IT !!! thanks for the help. Is that actually as tricky as it seems or was I just not paying attention?
Ben Reynolds
35,170 PointsHaha believe me, one day you will look back on this one and go "how did i not see it??" Try not to facepalm as hard as I did :)
It gets easier, but there's no secret trick to it. Just gotta practice practice practice and over time it starts to stick.
Conner Williams
Courses Plus Student 3,305 PointsConner Williams
Courses Plus Student 3,305 PointsI'm still having trouble with completing this. I thought I understood your suggestion but it isn't translating for me.