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 trialJudy Zhu
Courses Plus Student 323 Pointsdifference between the While loop and the Do While loop
What is the difference between the While loop and the Do While loop? and how am I suppose to know which one to use?
1 Answer
Michael Hulet
47,913 PointsThe only difference between the while
and the do while
loop is that the condition in a while
loop is evaluated before the code in the loop is run, where as it's evaluated afterwards in a do while
loop. In other words, the code in a do while
loop is guaranteed to run at least once. Otherwise, it's totally up to you which loop you want to use