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 trialShubham Modi
5,799 Pointsfor loop condition what to put
I need you to help me finish my loopy function. Inside of the function, I need a for loop that prints each thing in items. But, if the current thing is the string "STOP", break the loop.
def loopy(items):
# Code goes here
thing = input("> ")
for thing in items:
print(thing)
if thing == 'STOP'
break
2 Answers
Özgür Ozan Çakmak
11,451 PointsAlso you need to put a colon after the if statement and indent the break:
if thing == 'STOP':
break
Benedictt Vasquez
2,130 PointsI tried this and it works, but I can't passed the challenge.
def loopy(items): for thing in items: if items == 'STOP': break else: print(thing)
Jeremy Hill
29,567 PointsJeremy Hill
29,567 PointsFor starters you don't need any input from the user- you just loop through checking each item in the iterable that is passed in. Also, before you print you probably need to check to see if the current item in the loop is 'STOP' and if it is then break otherwise you print the item.
I hope this helps.