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

chris densmore
chris densmore
1,403 Points

Need help! Hey I feal like I have the right code here but keep getting error. Can someone please help me out.

Greatly appreciate it!

breaks.py
def loopy(items):
    # Code goes here
    for items in items:
        print(items)
        if items == "STOP":
        break
    else:
        print(items)

2 Answers

Clayton Perszyk
MOD
Clayton Perszyk
Treehouse Moderator 48,850 Points

Hey Chris,

You need to indent your break statement, as spaces are important in Python:

def loopy(items):
    # Code goes here
    for items in items:
        print(items)
        if items == "STOP":
          break # <------- here's the fix for the error you're getting
    else:
        print(items)

Best,

Clayton

Clayton Perszyk
Clayton Perszyk
Treehouse Moderator 48,850 Points

As shubhamkumartrivedi mentions, you should also change your for loop, so it isn't using the same variable for both the array member and array.

shubhamkt
shubhamkt
11,675 Points

Remove "items in items" and replace it by "for new_variable_name in items" remove the first line in the for loop i.e. print(items). replace items by new_variable_name i.e. if new_variable_name =='STOP': break else: print(new_variable_name) " the code goes as: def loopy(items): # Code goes here for item in items:

    if item == "STOP": break
    else:
    print(item)