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