Skip to main content

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.

Tags
Submitted by arilio666 on October 6, 2021

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.

About

At ProgramsBuzz, you can learn, share and grow with millions of techie around the world from different domain like Data Science, Software Development, QA and Digital Marketing. You can ask doubt and get the answer for your queries from our experts.