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 trialibrahim Warsame
7,803 PointsI 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
Evan Demaris
64,262 PointsHi 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!
ibrahim Warsame
7,803 Pointsthansk