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

Berluis Cabrera
PLUS
Berluis Cabrera
Courses Plus Student 443 Points

What´s wrong with my code?

The 'if' condition is giving me an error, what´s the matter?

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

    if loopy == 'STOP':
        break 

1 Answer

Keenan Johnson
Keenan Johnson
13,841 Points

Currently, it looks like your if statement is outside the for loop and so the for loop is never actually running the check to see if the value of the current item being iterated over is "STOP". Try nesting your if statement inside the for loop.

Solution:

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