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 Second Shopping List App

Is using "continue" necessary?

The instructor is using "continue" to "move on to the next step of the loop". Is this necessary? My program seems to run as expected without that line on either the "SHOW" or "HELP" portions of the loop.

If someone could lend some additional information on this - specifically why its working without that information, and why I may want to add it into my code - it would be greatly appreciated.

Thank you!

3 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! My guess here is that you haven't tried all possible scenarios without the continue. I encourage you to try commenting out the continue at SHOW part. When you do that and start the program, then immediately enter SHOW here's what happens:

> SHOW                                                                                                            
Here's your list:                                                                                                 
Added SHOW. List now has 1 items.

Because the continue would force it back up to the top of the loop and skip over adding the item "SHOW". But because it's now commented out, that doesn't happen so it actually gets added to the list. Hope this makes sense! :sparkles:

I don't seem to have that issue. No matter what combo of entries I've tried, including your suggestion, I can't duplicate that issue.

Here is the code of the main loop:

shopping_list = [] 
item_total = 0

while True:
    item = input("Add: ")
    if item == "DONE":
        show_list()
        break
    elif item == "SHOW":
        show_list()
    elif item == "HELP":
        show_help()
    else:
        shopping_list.append(item)
        item_total += 1
        print("Added: {} to your list. \nThere are currently {} items in your list\n".format(item, item_total))

Note, I coded this during the "pause and see if you can figure it out yourself..." section. The only part I added after watching the video was the "verification" line of code that displays the item you added and your current number of items. Perhaps my version (though I don't think its very different from the instructor's) prevents this from happening...?

I appreciate your help!

Sneha Nagpaul
Sneha Nagpaul
10,124 Points

Maybe you are not using elif statements but rather separate if statements.

You don't need to use continue since you're appending to the list in an else block.