Translation Do-while loops in JavaScript

Source: Internet
Author: User

This article translates the JavaScript Tutorial playlist of up master Kudvenkat on YouTube

SOURCE Address here:

https://www.youtube.com/watch?v=PMsVM7rjupU&list=PL6n9fhu94yhUA99nOsJkKXBqokT3MBK0b

In this video we will use examples to discuss the Do-while loop in JavaScript, in Chapter 16 we discuss the while loop

While loop:

1.while Loop First Check condition

2. If the condition is true, the statement in the loop executes

3. This order repeats until the condition is false.

Do-while Cycle:

1.do-while Cycle in the final check condition of the cycle

2. This means that the Do-while cycle ensures that at least one cycle can be performed

3. In general, the Do-while loop is used to show the User a menu

The difference between the while loop and the Do-while loop:

The 1.while loop checks the condition at the beginning, and the Do-while loop checks the condition at the end of the loop

The 2.do-while cycle is guaranteed to run at least once, but the while loop is not

Do-while Cycle Examples:

varUserchoice = ""; Do {    varTargetnumber = number (Prompt ("Please enter your target number", "" ")); varStart = 0;  while(Start [=Targetnumber) {document.write (Start+ "[br/]"); Start= Start + 2; }     Do{Userchoice= Prompt ("Do 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");

Translation Do-while loops in JavaScript

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.