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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Stephen Hancock](https://secure.gravatar.com/avatar/7dbb8a988aef0c62030b2a954da97a4f?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Stephen Hancock
4,888 PointsWhile - not sure why we won't know when the loop will end.
So at the end of the video it says we don't know when the loop will end when using 'while'.
Now I think I understand if we were just using 'while' and maybe that was what the video was referring to, but we have defined an end point to the loop by adding the sys.ex. when the user has too many invlalid password attempts.
I either don't fully understand how the loop is working or I am misunderstanding the comment.
1 Answer
![Jeff Muday](https://uploads.teamtreehouse.com/production/profile-photos/5900142/micro_jeff_face.jpg)
Jeff Muday
Treehouse Moderator 28,718 PointsNice catch, you are a very observant viewer! The "while" loop keeps running until a condition is met. But, the code slightly contradicts what he is saying since it would EXIT to the system after three incorrect attempts. The EXIT (sys.exit() function) is part of the loop but it "short-circuits" the while loop-- like an escape hatch!
At around 9:30 in the video Craig is attempting to convey that this particular while loop will continue looping until the user correctly matches the MASTER_PASSWORD. He is saying that it might run only one time, but could also run two times, or three times-- it all depends on what the user types. In fact, the user may never get the correct password in three attempts and it will just EXIT.
He is setting up the next video in the sequence where you will use the "for" loop which typically is looping over a finite number of elements.
Stephen Hancock
4,888 PointsStephen Hancock
4,888 PointsThanks for clarifying this Jeff, it is really helpful.
I thought this might be the case but I didn't want to assume, and carry on with potentially an incorrect understanding.
I like the anology of the (sys.exit() fucntion) 'short circuting' the while loop. It is a helpful anology to 'visualise' how this works.