Skip to main content

//while loop

While Loop 


  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title></title>
  6. </head>
  7. <body>
  8. <script type="text/javascript">
  9. //while loop
  10. //print number from 10 to 20
  11. var a = 10;

  12. while(a <= 20) //(a=10 <= 20) the condition is True; therefore excute conditional code.
  13.               //when condition is true then excute conditional code; otherwise loop body skipped.
  14. {
  15. //the body of loop
  16. document.write("the value of a is:"+a+"<br>")
  17. a++; // a++ for this condition 'a <= 20'. value increase upto 20.
  18. }
  19. </script>
  20. </body>
  21. </html>



//Excute


//Output

/*the value of a is: 10

the value of a is: 11

the value of a is: 12

the value of a is: 13

the value of a is: 14

the value of a is: 15

the value of a is: 16

the value of a is: 17

the value of a is: 18

the value of a is: 19

the value of a is: 20*/






                                     //ThE ProFessoR