Support us .Net Basics C# SQL ASP.NET Aarvi MVC Slides C# Programs Subscribe Download

do while loop in JavaScript

Suggested Videos
Part 14 - Switch statement in JavaScript
Part 15 - Ternary operator in JavaScript
Part 16 - Loops in JavaScript



In this video we will discuss do while loop in JavaScript with an example. In Part 16 we discussed while loop. Please watch Part 16 before proceeding.



while loop :
1. while loop checks the condition first
2. If the condition is true, statements with in the loop are executed
3. This process is repeated as long as the condition evaluates to true.

do while loop :
1. do while loop checks its condition at the end of the loop
2. This means the do...while... loop is guaranteed to execute at least one time.
3. In general, do...while... loops are used to present a menu to the user

What is the difference between while and do while in javascript
1. while loop checks the condition at the beginning, where as do...while... loop checks the condition at the end of the loop
2. do...while... loop is guaranteed to execute at least once, where as while loop is not.

do while loop example

var userChoice = "";
do
{
    var targetNumber = Number(prompt("Please enter your target number", ""));
    var start = 0;
    while (start <= targetNumber)
    {
        document.write(start + "<br/>");
        start = start + 2;
    }

    do
    {
        userChoice = prompt("Do you want to continue - Yes or No").toUpperCase();
        if (userChoice != "YES" && userChoice != "NO") {
            alert("Invalid choice. Please say, Yes or No");
        }
    } while (userChoice != "YES" && userChoice != "NO");

} while (userChoice == "YES");

JavaScript tutorial

7 comments:

  1. Print ASP.Net Panel contents(including images) with Print Preview using JavaScript .

    ReplyDelete
  2. can anyone help me please ..

    how to make bubbles on image by each button click event .

    keep explore the treasure of knowledge

    thanks and regards

    ReplyDelete
  3. Jquery accordion is not working on post back?
    how can i make accordion work on post back and Partial Post back

    ReplyDelete
  4. javascript coordinates for each mose click on DIV to place one lable on DIV

    ReplyDelete
  5. Dear Vankat!
    A long time has passed but there is no new updates is outcome is it all right?
    We are tense about you.
    May GOD Bless you!

    ReplyDelete
  6. hi venkat sir ,
    please a make tutorial on NUnit testing in .Net.

    ReplyDelete
  7. Hi Venkat Sir,
    Heartful thanks to such a great tutorial with wonderful explanation. i learnt lot from your videos. Please provide the video tutorial on NUnit Testing , Session state modes, SSRS reports in visual studio 2010. it helps a lot to me and community. . please

    ReplyDelete

It would be great if you can help share these free resources