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 trialFHATUWANI Dondry MUVHANGO
17,796 Pointsi need help
i think i'm missing something.... here's my code
def loopy(items): for item in items: print(item) if items == "STOP": break
def loopy(items):
for item in items:
print(item)
if items == "STOP":
break
4 Answers
Benjamin Lange
16,178 PointsBefore you print the item out, you want to first check if the item is "STOP". You need to put the if statement at the top of the for loop.
FHATUWANI Dondry MUVHANGO
17,796 Pointsok i tried doing what you said, there is still something wrong
def loopy(items): if items == "STOP": break for item in items: print(item)
Benjamin Lange
16,178 PointsYou want the if statement to be inside of the for loop but before the print(item).
FHATUWANI Dondry MUVHANGO
17,796 PointsOk I've been trying and using your idea Benjamin, but its not working. And I feel that there is something small that I'm missing
Benjamin Lange
16,178 PointsHere's what you want to do:
Start the for loop like you've already done. The first line of code under the for loop needs to be your if item == "STOP". Make sure that you're checking item and not items. If it is, break, otherwise print item.
FHATUWANI Dondry MUVHANGO
17,796 PointsIt worked!! Thank you very much