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 trialkushagra jain
Courses Plus Student 2,563 PointsCan't find any error?
challenge task 2 of 2 1st coding challenge on list
def loopy(items):
for item in items:
print(item)
if item == 'STOP':
break
3 Answers
Van Sanders
16,087 PointsThe only thing is that you print before you check if the item == 'STOP'
Check for that condition first and break if the condition is met, ELSE: print(item)
:)
Ari Misha
19,323 PointsHiya Kushagra! The order matters in your loop. The first statement loop encounters in its block , will get executed first. So when your "for" loop will get to your "if" condition, it has already "printed" out all the values for "item" alias, so yeah it wont even get to the condition and "break" statement in the condition. Your code should look something like this:
def loopy(items):
for item in items:
if item == 'STOP':
break
print(item)
kushagra jain
Courses Plus Student 2,563 PointsThank you so much for clearing my doubt!!!!