Welcome
Login / Register

do while loop in JavaScript

Featured video
You need to have the Flash Player installed and a browser with JavaScript support.

Thanks! Share it with your friends!

URL

You disliked this video. Thanks for the feedback!

URL


Published by Admin in Java Script
1,037 Views

Description

Link for all dot net and sql server video tutorial playlists
http://www.youtube.com/user/kudvenkat/playlists

Link for slides, code samples and text version of the video
http://csharp-video-tutorials.blogspot.com/2014/11/do-while-loop-in-javascript.html

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");

Show more

Post your comment

Comments

Be the first to comment