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.
Stephen Hancock4,888 Points
While - 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.
Jeff MudayTreehouse Moderator 26,984 Points
Nice 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.