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 (Retired) Shopping List Shopping List Project

Michael Strasser
Michael Strasser
3,073 Points

Why use "continue"?

I really enjoy your teaching style and the other videos, but I have to point out, that this is a horrible way to teach people about loops. I don't think it's considered "good practice" to use infinite while loops. There may be cases where an infinite loop with a "break" statement might be the best thing to do, but in most cases it is not! I don't think it's wise to teach people who are new to programming that it's good to use infinite loops. Yes, if we wouldn't have used an infinite loop this script would have been a bit more complicated, but usually you really should put a logical statement in the loop condition.

The second thing which is just blatantly wrong is the explanation of "continue" at the end of the loop. The loop will continue anyways when the end of the while block is reached! Putting the continue statement there is just wrong, you would use the continue statement in a case where you have some sort of if-condition and then you want to jump over the rest of the loop block.

For example:

while new_item != "DONE":
     if new_item == "Apple":
        my_list.append("Apple")
        continue
     my_list.append(new_item)

Maybe this is explained in the upcoming videos in greater detail and all of this will be corrected. But a little sidenote, that this is a simplified example and you shouldn't code like this if you write a "real" program would be really great.

[MOD: added ```python formatting -cf]

2 Answers

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

And, FWIW, infinite while loops are amazingly common in lower level programming. Games programming, long running applications like the ones we built in Python Basics and the other first few Python courses, and even things that you just need to run until you quit them, even though they have an internal timer that slows or interrupts their processing (like a script that pings an external point), need and use infinite loops. I agree that they're not the most sophisticated way of accomplishing a goal, but that doesn't mean they're a bad thing to teach or the wrong way to go about it.

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

Yeah, it was a mistake that we didn't catch until after the course was out and like. We have a complete refresh of Python Basics underway that should be out before the new year that addresses this and some other concerns.