do-while-3

 

Example of JavaScript do-while loop calculating the sum of numbers:

 
 
 
<!DOCTYPE html> <html> <head> <title>Welcome to LearnKode - A code learning platform</title> </head> <body> <button type="button" onclick="calculateSum()">Show the sum</button> <script> function calculateSum() { var sum = 0; var number = 1; do { sum += number; number++; } while (number <= 50); alert("Sum = " + sum); } </script> </body> </html>
Output