Friday , 22 February 2019
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


Audio – Advanced JavaScript Tutorial

The video and audio objects both have the same events, properties and methods. So, you …

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.