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 Shopping List Introduction

Dongyun Cho
Dongyun Cho
2,256 Points

what is difference between return False and break in if loop?

shopping_list=[]
print("what should we pick up at the store?")
print("Enter DONE to stop adding items.")

while True:
  new_item = input("> ")  
  if new_item == 'DONE':
    print("Ok, Shopping list is done. ")
    return False

  shopping_list.append(new_item)

print('here\'s your list: ')
for item in shopping_list:
  print (item)

hi, I set if block that return False and I want to make while loop stop with that. cause while loop is running only when it;s True. but SyntaxError keeps turning up and saying "'return' outside function ". what does this error mean what is difference between return False and break in if loop?? pleae explain what they exactly do in loops and functions?

2 Answers

james south
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
james south
Front End Web Development Techdegree Graduate 33,271 Points

return tells a function to stop running and return a value and only resides in a function definition. you are not defining any functions (with the def keyword) so there is no use for the return keyword. you only have a loop and if you want to stop it use break.