While and do-while loops

While loops
While loops repeat sections of code until a condition is met. While loops test the condition first before running, so make sure the variable in the check is initialized!

Here's an example of a while loop that uses a number in its check:



Here's an example of a while loop that uses a char to check if it should keep going:



do-while loops
Unlike while loops which check before running, do-while loops check at the end of their loops. Therefore, do-while loops always run at least once. A nice thing about do-while loops is that you can use a variable that isn't initialized until you're inside the loop instead of having to put a dummy value in before running your loop.

Here's an example of a do-while loop: