JavaScript: Do...While loop

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.

Wed, 10/06/2021 - 10:32

Authored by

Ashwin is working with iVagus as a Technical Lead. He has experience in various technologies like Cypress, JavaScript, TypeScript, Rest Assured, Selenium, Cucumber, and Java.
Tags