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 trialAlex Durham
Courses Plus Student 456 Pointsbreak
can someone help me with the break thanks!
def loopy(items):
for item in items:
print(item)
if item == 'STOP':
break
2 Answers
james south
Front End Web Development Techdegree Graduate 33,271 Pointsyou are close, your indentation is off, the if block is under the loop not in it, so tab it over. then you will need to break before printing the item so check the string and break if needed, else print the item.
Alexander Davison
65,469 PointsYour if
statement is outside the loop. It should be inside the loop!
Try something like this:
def loopy(items):
for item in items:
if item == 'STOP':
break
else:
print(item)
Steven Parker
231,248 PointsSteven Parker
231,248 PointsRemember to mark the question closed (by selecting a "best answer") once you are satisfied with an answer.