Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Collections (Retired) Lists Redux Shopping List Take Three

I didnt understand the whole code. please explain this lesson for me.

I mean the code in the video. espicaley the while loop part.

2 Answers

Hi Ibrahim,

The while True loop is essentially a circular bit of code that says; loop this code forever.

In the video, he shows you things that you'll want to include in the while loop for that program; basically, what do you want to happen again and again? The exacts aren't actually super important to understand the concept behind the loop, just that you will have code that makes sense to loop through repeatedly.

Do you want your program to ask for groceries until you tell it you're done? Do you want it to display some other text until you've given it the appropriate response? Do you want it to do some math on whatever you've input, and keep calculating as long as you keep giving it input?

He also includes a way to break out of the loop, so you don't have to close your interpreter just to make it stop. There are more than one ways to break a loop, but if you decide to set your while loop to True - not giving it any parameters - then it is very important to include a way to break that loop to the user of the program (exiting the program or moving to a different loop or block of code to be executed).

It's also important that the way to break the loop isn't difficult for the user to figure out.

I hope that helps!

thansk