Python Python Basics (2015) Shopping List App Shopping List Introduction

Robert Baucus
Robert Baucus
3,400 Points

(Python3.6) ShoppingList program gets 'break' error

I got the program to run using a while loop but I am having a problem getting it to run using a function. I have gone through it a couple times and think it looks ok, but I keep getting a " syntaxError: break outside loop" , this is what I have:

print("Let's make a shopping list, breh!")
print("Add new items one at a time, type, 'DONE' to finish")

shopping_list = []

def shopping():
    new_item = input("> ")
    if new_item.upper() == 'DONE':
    return shopping_list

print("Here's your shoping list, breh!")

any ideas?

1 Answer

akhter ali
akhter ali
15,778 Points

break is not meant for if/else condition, break is meant to break out of for/while loops. Your break statement is invalid.

Take the example from the link below, break is breaking out of the inner for loop and only runs if the condition is True/False