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

Antonie Huang
Antonie Huang
985 Points

How to use the for loop to print out item? And what does the question mean? How do I "Break"?

I don't quite understand the question on for loop and break.

breaks.py
def loopy(items):
    # Code goes here

2 Answers

Carlos Federico Puebla Larregle
Carlos Federico Puebla Larregle
21,074 Points

You have to use a for loop to "see" every item in that variable "items" which is the variable that you have received as an argument. Inside that for loop you have to check if the current thing is equal to the string "STOP", if that is true you have to break out of the loop, other wise you have to print the thing. You could do it like this:

def loopy(items):
    # Code goes here
    for thing in items:
        if thing == "STOP":
            break
        print(thing)

I hope that helps a little bit

Antonie Huang
Antonie Huang
985 Points

What about the word "thing" is that just a word for computer to know there is something there?

Carlos Federico Puebla Larregle
Carlos Federico Puebla Larregle
21,074 Points

The for loop is used to check/see every item inside of an iterable. In order to do that you have to use a variable that is going to hold the current item of that iterable that you're checking. You can use any name, "thing", "item", anything that represents the current "thing" in the iterable.

for item in items:
    print(item)

I hope that helps a little bit.