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 Introducing Lists Build an Application The Application

Iulia Maria Lungu
Iulia Maria Lungu
16,935 Points

The use of continue in the given example

I don't really get the point of using the continue keyword in the specific place where it's used because it's anyway placed at the end of the statement so there's no other code to run after the continue, so the loop would actually continue by itself, isn't it? Am I missing something?

UPDATE: Seeing the answers made me think that I must paste the code that i am referring to cause you might be thinking that I am asking about the use of continue in general, but my question was meant for this specific code:

while True:
    new_item = input("> ")
    if new_item == "DONE":
          break:
    elif new_item == "HELP":
          show_help()
          continue

4 Answers

unknown member
PLUS
unknown member
Courses Plus Student 18,949 Points

At this point it should be a bit unclear, but calling 'continue' will put you back to 'while True' line immediately and in this way you'll avoid putting 'HELP' keyword to your grocery list. On the other hand, you can put (for example) 'add_to_list()' function into 'else:' statement and in this case you won't need those two 'continue' anymore. Of course 'add_to_list()' function won't work by default, it must be defined beforehand.

Ahmed Khairi
Ahmed Khairi
2,113 Points

basically, at this stage, it doesn't matter if continue typed on not the loop will iterate but always we have to make sure the code is clean

I actually had the same question in my mind when i saw the code. I think he uses continue just for demonstration purposes since we did not have it mentioned before in the Python Beginning Course. In this case I suppose it has no effect to the code.