Welcome to the Treehouse Community
Looking to learn something new?
Vic Mercier3,276 Points
When would I couldn't use a while loop instead of the do while loop?
I don't really understand.
Loops can be confusing at first - the short answer is that you generally CAN use a different type of loop for most situations, depending on how you structure your code.
The main thing to keep in mind is that certain loop types can be easier to code/easier to read in certain circumstances. Do-while loops can be useful when you know you want the code to run at least once (a while loop will not run at all if the condition it checks for is false beforehand, but a do-while loop will run once before it checks). A for loop is one of the easier ones to read and organize when you want a loop to repeat a particular number of times using a counting variable. You can do this with a while loop too, but a for loop can look cleaner and more organized. Finally, a while loop is best when you want the code to run only when certain conditions are met, and stop when they're not.
As you keep coding, you'll start to see circumstances that fit the different loop types. Sometimes you'll run into a scenario where it's really just up to your preference.
Hopefully this helped clear things up a little bit - happy coding!