Break statement:
The code is as follows |
Copy Code |
<script type= "Text/javascript" > for (Var i=1;i<=10;i++) { if (i==6) break; document.write (i); } Output Result: 12345 </script> |
Continue statement
The code is as follows |
Copy Code |
<script type= "Text/javascript" > for (Var i=1;i<=10;i++) { if (i==6) continue; document.write (i); } Output Result: 1234578910 </script> |
Now let's look at the difference between break and continue.
The loop statement used to terminate a loop that is broken after a break statement will not be executed as:
The code is as follows |
Copy Code |
<script type= "Text/javascript" > var i=0; for (I=0;I++;I<10) { if (i==3) Break document.write (i); } </script> |
The result of the output is
0 1 2
The continue statement is used to terminate the current loop. The current loop is terminated but the subsequent loop is executed as
The code is as follows |
Copy Code |
<script type= "Text/javascript" > var i=0; for (I=0;I++;I<10) { if (i==3) Break document.write (i); } </script> |
The result of the output is
0 1 2 4 5 6 7 8 9
special usage of break,continue
code is as follows |
copy code |
var result = False Point: { var obj = {Key:1}; for (var key in obj) { //... Break point; } result = true; } Alert (result); |