• Monday , 24 July 2017

do while loop in JavaScript

Code Canyon



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

Original source

3d Ocean

Related Posts

21 Comments

  1. Bala Kumaar
    June 23, 2017 at 02:54

    Hi Venkat,

    This program is not working correctly..!!!

    >>> First the prompt box is opening ,once i have entered the number and click OK ,it quickly asking "Do you want to continue -yes or No"..the numbers is not displaying in browser..

    I have attached the code below…!!

    CODE :
    ————————————————————————————————————————————————————————————————
    var ques = " ";
    do {
    var user = Number(prompt("Please enter the number", " "));
    var start = 0;

    while (start <= user) {
    document.write(start + "<br />");
    start = start + 2;
    }

    do {
    ques = prompt("Want to continue – Yes or No");
    if (ques != "Yes" && ques != "No") {
    alert("Please enter Yes or No");
    }
    } while (ques != "Yes" && ques != "No");

    } while (ques == "Yes");
    —————————————————————————————————————————————————————————————–

  2. Ashish Patel
    June 23, 2017 at 02:54

    Thanks for all your work. Helping me a lot.

    Instead of Number(prompt()), can you help me on how to use it through function with onclick event and also adding # through text box in webpage?

  3. Aditi Mohpal
    June 23, 2017 at 02:54

    This is awesome as always..thanks alot..once i am done with javascript tutorial i want to learn jquery. Will you be able to upload videos on jQuery ?

  4. Moses Dwana
    June 23, 2017 at 02:54

    i am learning a lot from you!! thanks very much

  5. chatarji arjampudi
    June 23, 2017 at 02:54

    hi.. i'm unable to find ur blog. it is showing blog not found

  6. himanshu rastogi
    June 23, 2017 at 02:54

    Hi venkat when U upload new video of javasript series……

  7. mahipal kamanchi
    June 23, 2017 at 02:54

    sir why u stopped  videos pl upload we are eagerly waiting for u videos….! 

  8. prasad kammili
    June 23, 2017 at 02:54

    sir, i addicted to your tutorials please share next one.. thanks alot…

  9. naveen murari
    June 23, 2017 at 02:54

    we are you…..

  10. manoj barwal
    June 23, 2017 at 02:54

    plz upload next video

  11. Kiran Pedamkar
    June 23, 2017 at 02:54

    As usual, Great.

  12. Munakala Dillesh
    June 23, 2017 at 02:54

    thank you sir because of you I learned alot

  13. Mahmud
    June 23, 2017 at 02:54

    Sir, upload the next video

  14. manish kumar
    June 23, 2017 at 02:54

    hiii  sir where  are  you?????

  15. Abhishek Gupta
    June 23, 2017 at 02:54

    Where are you sir we are waiting for you

  16. Srinivas Chandra
    June 23, 2017 at 02:54

    hi Venkat.,

    here is my interview questions .
    1.How would I get alert if my credential already being used by some other user? 
          Eg: suppose I have share my user/pw to some other and he loged in with those credentials. in this case if I loged in with same credentials I should get alart at my end.

    my answer : we can have to create a flag column in database table and we do with it.

    but he said not like this (classic).

    2.How do we hide the file extension in url.
    my answer is "url redirecting" .

    he said no..

    Can u pls give you suggestion for the same.

  17. Srinivas Chandra
    June 23, 2017 at 02:54

    Hi Venkat.,
    can u pls some more vedios for the same.

  18. akanbi awwal
    June 23, 2017 at 02:54

    just seeing your post in javascript made me pend other materials in js.you always have well presented tutorials.tanks a lot

  19. akanbi awwal
    June 23, 2017 at 02:54

    very great sir.pls we still need more of this.should we be optimistic?

  20. Jitendra Mahapatro
    June 23, 2017 at 02:54

    is this last java script video?

  21. Jitendra Mahapatro
    June 23, 2017 at 02:54

    nice.

Leave A Comment

You must be logged in to post a comment.