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 trialgibran erlangga
5,539 Pointsdo you guys have any idea on what "for" syntax code should look like in order to solve this problem?
I'm having difficulty in understanding this topic. The example before is using 'while', and now they want me to create the same code output using 'for'.
def loopy(items):
for items in items:
new_items = input("> ")
items.append(new_items)
if new_items == "STOP":
break
# Code goes here
1 Answer
jcorum
71,830 Pointsgibran, try this:
def loopy(items):
for thing in items:
if thing == "STOP":
break
else:
print(thing)
gibran erlangga
5,539 Pointsgibran erlangga
5,539 Pointssolved! many thanks to you, jcorum!