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.
do...while - why would I want to rewrite this question?
I'm on the challenge asking us to rewrite a while loop into a do ... while loop.
I got the solution, but I still don't understand why I would use a do...while loop in this situation.
Given the existing code, the first thing we are doing is setting up a variable and prompting the user to enter a password. Then we are in the while loop as long as the entered password doesn't match the stored password.
There is no possible way to not get into the while loop because at load, the password is blank and therefore always meets the condition of the while loop (it does not equal the correct password).
If the whole point of a do... while loop is to make sure the while loop executes at least once, why would we use it in this scenario. In this case the while loop will always run regardless.
I understand what a for...while loop does. I was just commenting that in this example, it doesn't make a lot of sense to use it. Even if the goal was to make the code more "DRY", there are better ways to do it.
Also, I've heard the suggestion that it's better to use MDN as a resource as it a respected/peer reviewed/ professional reference, while w3schools can be a bit "iffy" (even though most of the stuff on there is right).
MDN is cool, but in my opnion it takes time to get used to their way of teaching