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
Jassim Alhatem
20,883 PointsWhile Loops
I'm getting different results from these two and I thought they meant the same thing. For example, if I say while variable: does that mean while the variable is true?
So What's the difference:
''' while True: '''
and
''' while variable: '''
1 Answer
Chris Freeman
Treehouse Moderator 68,468 Pointsif I say while variable: does that mean while the variable is true? Yes. Using while variable: means while the value of the variable is "truthy", that is, evaluates to a non-zero value. For objects like lists and strings, it means "non-empty". The list [] and the empty string "" will be considered false. All other lists and strings are considered "True".
The loop while True will not end, unless a break statement is reached.
Post back if you need more help. Good luck!!
Jassim Alhatem
20,883 PointsJassim Alhatem
20,883 PointsI gotchya, cheers Chris!