The while loop runs if the condition at the top is true, but you might have a case when you need to run the code in the loop at least once, or you need to test the condition at the end of the loop.
The solution to this is the do...while loop. The do...while loop is identical to the while loop, except the condition statement is tested at the end. As a result, the loop will always run at least one time, and if the condition at the end of the loop is true, the loop will repeat. If the condition at the end is false, it will not repeat the loop, and the flow of the program will continue with the next statement.
Creating a do…while Loop
In this example, the loop will run five times, starting with the value 5 and then decrement that by 1 with each execution of the loop.