Skip to main content

//Break And Continue Statement

Break And Continue Statement



  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. var a = 10;

  10. while(a <= 20)
  11. {
  12. if (a == 15) //(a==15)when... block of code to be executed if the condition is True. 
  13. {
  14. a++;
  15. document.write("in if statement of a is:"+a+"<br>")
  16. break; //Break :- when the loop iterates for first time, the value of i=10, the if statement result will be false, so the else condition is executed.
  17.   //loop iterates again now i=15; if condition result will be 'True' and loop breaks.
  18.      //you can also use 'Continue' 
  19.     //Continue:-when the loop iterate for the first time the value of i=10, the if statement result will be false, so the else condition 2 is implemented.
  20.    //loop iterates again now i=15; if condition result will be 'True' and the code stop in between and strat new iterate unitl the end condition met.

  21. }
  22. document.write("the value of a is:"+a+"<br>")
  23. a++; // a++ for this condition 'a <= 20'. value increase upto 20.
  24. }
  25. </script>
  26. </body>
  27. </html>


//Execute


//Output


 //for continue

/* 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

in if the statement a is:16

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 */



//break 

/* 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

in if the statement a is:16 */





                                      //ThE ProFessoR