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

Using break

Can someone please explain to me the difference between the two code pasted. I answered it but not quiet clear with the result.

def loopy(items):
#if items == 'quit':

for item in items:
    if items == 'STOP':
        break
    print(item)

loopy('STOP')


def loopy(items):
#if items == 'quit':

for item in items:
    if item == 'STOP':
        break
    print(item)

loopy('STOP')

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

2 Answers

items is your list. item represents the individual contents in the list. You could change the word item to almost any word you like but items is the name of the list you are using. If you added another list to your code...

items = ["apple", "bannana", "STOP",]
other_items = ["spoon", "fork", "knife",]

for item in other_items:
    if item == 'STOP':
        break
    print(item)

... and used the other_items list instead, you would print out... spoon fork knife ...instead of the contents of the items list that you are currently printing. items can't == 'STOP' because items is the list but one of the item in items is 'STOP'.

Taylor, thanks for your explanatory, much appreciated..