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 trial

Python Python Basics (2015) Shopping List App Break

Debdipta Dasgupta
Debdipta Dasgupta
431 Points

How to solve this challenge

Can't understand where I am going wrong. Thanks in advance.

breaks.py
def loopy(items):
       if items=="STOP":
                  BREAK
          for man in items:
                 print(man)

1 Answer

Ryan Ruscett
Ryan Ruscett
23,309 Points

Hey,

it's like this

  1. We need a for loop to iterate over the items. So this means the first thing we do is iterate over the items.
def loopy(items):
    for item in items:
  1. Now, if item is STOP we need to break the for loop
def loopy(items):
    for item in items:
        if item == "STOP":
             break
  1. If the item isn't STOP than we need to continue to print the items.
def loopy(items):
    for item in items:
        if item == "STOP":
             break
        print(item)

Does that make sense?