Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Do While Loop in Javascript

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 320
    Comment on it

    Do While loop Executes a statement once, and then it repeats the execution of the loop until a condition expression becomes false.

    The do while loop consist-

    do {
        statement
    }
    while (expression) ; 
    

    statement--> The statement to be executed if expression is true.
    Expression --> It relates to Boolean ,it shows true or false. If expression is true, the loop is executed otherwiseit is terminated.

    We can also use the break statement in the do while loop . It cause the program to exit from the loop. Below is the example of the loop-

        <!DOCTYPE html>
        <html>
        <body>
    
        <p>Click the button</p>
    
        <button onclick="myFunction()"> Click Here</button>
    
        <p id="button"></p>
    
        <script>
        function myFunction() {
            var text = ""
            var i = 0;
            do {
                text += "<br> " + i;
                i++;
            }
            while (i < 10)  // it will run to loop from 0 to 10
            document.getElementById("button").innerHTML = text;
        }
        </script>
    
    </body>
    </html>
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: