How to use Do While loop in JavaScript

In this article I am going to explain about do while loop in JavaScript.
  • 2066

JavaScript do while loop

Do while loop is also a type of loop. In this this loop statement will be executed minimum one time because do while check condition at end of loop. its execute block of code until given condition is true.

Do while loop syntax

do
{

    //Your statement here

}
while (Variable> condition);

In this example it will display 1 to 10 natural number through do while loop

<html>

<head>

    <script type="text/javascript">

         function MyFunction() {

            do {

                document.write(i + ",");

                i++;

            }

            while (i < 11);

        }       

    </script>

</head>

<body>

    <button onclick="MyFunction()">

        Click</button>

</body>

</html>

 

Output


foeloop.jpg


Further Readings

You may also want to read these related articles: here
Ask Your Question 
 
Got a programming related question? You may want to post your question here
 

Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.