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 trialJessica Yan
700 Pointswhile True:
What does while True mean? What does the True refer to here as being truthy?
2 Answers
Sara Watson
Courses Plus Student 3,713 Pointswhile True: Means that you want the code within this while block to continuously execute, always. True is never False so it will loop forever.
William Gough
18,852 PointsUntil break
is executed inside the loop.
furkan
11,733 PointsHello Jessica Yan,
In this video, Kenneth used the while loop which is a way of running a set of codes over and over again. The codes that run are shown under the while true loop, which is more technically called a "code block". Now, a while loop always tests for a condition before it runs the code block under it, in this case, the condition is always True, because he has simply said >>> while True:
Therefore, the code block runs. However, he has another condition he is testing for, which is >>>
if guess == secret_num
This time he is testing to see if he guessed the number right. And if he did guess it right, then the game should end. So, a neat trick to get out of an infinite loop, in this case, while True: we use a break
A break statement ends the loop and exits out of it.
Hope this helped, all the best, Furkan.
juliansteffen
9,802 Pointsjuliansteffen
9,802 PointsHello Jessica,
I might don't understand your question 100%. But in generel while True: means : while is a keyword for a "Loop-function" true is a boolean => it has just two stats 0 or 1 => true or false
The keyword while needs some Information "how long" it should loop the following block of code. With true you tell him "forever" there is no check for the while keyword if it should loop or not..just "hardcoded" run! If you would while False: ...it would never run.
True is no check to somewhere else. We tell just while run please :) anyway.
Greetings Julian