JavaScript: Do...While loop

Profile picture for user arilio666

Similar to while do while no matter what, it runs the loop without the satisfaction of the condition first and checks for the state at the end whether it needs to satisfy or not.

Syntax

do
{

}
while();

Example:

let age = 1

do
{
    console.log("Age of " +age+ " is allowed!")
    age++
}
while(age < 5)

Output:

Age of 1 is allowed!
Age of 2 is allowed!
Age of 3 is allowed!
Age of 4 is allowed!

Same as while loop here, it checks and does the execution of the do body first no matter it is false or true. Then it checks the condition at the end in while state and supposedly decides whether to satisfy or not.