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 trialNeal Thomas
498 Pointsissue with break code.
i don't know what's wrong with the break code. please help
def loopy(items):
for item in items:
print(item)
if items == "STOP":
break
2 Answers
Thomas Fildes
22,687 PointsHi Neal,
There are two things that are preventing you from passing the challenge.
The first is your indentation, the if statement needs to be indented to show that is part of the for loop's block of code.
The second issue is the if statement needs to be placed before the print function because you need to check the condition whether the item equals STOP before you print the item.
Please see the code I used to pass this challenge:
def loopy(items):
# Code goes here
for item in items:
if item == "STOP":
break
print(item)
Hope this helps! Happy Coding!!!
Neal Thomas
498 Pointsthank you so much for explaining the mistake. :)