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 trialUnsubscribed User
3,120 PointsI don't understand the structure for blocks of code, I think.
I feel like the logic should be correct. I'm not sure why my code doesn't work.
def loopy(items):
for item in items:
print(item)
while item == "STOP":
break
1 Answer
Garrett Guevara
11,331 PointsHi Ezekiel,
You're really close here. But instead of a while loop, you'll need to use a conditional instead. My solution uses a:
- for loop to loop through the list items
- uses a nested conditional in the for loop that says
- if an item equals the string "STOP", it will break
- otherwise, it will continue printing each item.
def loopy(items):
for item in items:
if item == "STOP":
break
else:
print(item)
I hope this helps and happy coding!
Garrett