Wednesday , 17 January 2018
Home / Programming / JavaScript / Do While Loop – JavaScript Tutorial
Do While Loop
Do While Loop

Do While Loop – JavaScript Tutorial

This tutorial is part of the JavaScript tutorial series for beginners. To view the whole list of tutorials available and the order in which you should follow them, then click here.

A do while loop is a special kind of loop. It’s a variation of the while loop, but with a special addition. Let’s learn how to use a do while loop.

Creating A Do While Loop

Clear your script and update your code to this.

You’ll notice everything is the same in our last tutorial, except our loop is a tad different. A do while loop is structured with the keyword do at the beginning of the loop and the keyword while at the end.This is because a do while loop runs at least once before it checks the condition.

This is useful when you’re certain you want to execute the block of code at least once before running it again. You also have to add a semi-colon at the end of your while statement.  If you run this code, then you should get an alert message saying 100.


We’ve learned how to use the 3 main loops in JavaScript. In all the examples, we were able to achieve the same result. If’s up to you want to use the do while loop. Each loop is more useful for certain tasks than the other. There’s one more loop, but we haven’t talked about objects yet.


We’ve been talking about the basics for a bit and you may not fully understand the full capabilities of each loop yet. We still have some fundamentals to cover, but soon we’ll be practicing how to use these loops in real world situations and examples.

About Jasko Koyn

Check Also

Try-Catch Statement

Try-catch Statement – Advanced JavaScript Tutorial

The try-catch statement is a unique way to handle errors. When errors occur, usually it …

Leave a Reply

Your email address will not be published. Required fields are marked *

Want to learn how to create web applications with Node.js and SQL? Check out my course!
Get 93% off my course. You'll also learn how to build real world applications using Node and SQL. This is a limited time offer
Yes, I would like to get 93% off your course!
No Thanks!