JavaScript Break and Continue statements

JavaScript Break and Continue statements

In JavaScript, use the break and continue statements to jump out of the loop:

The function of the break statement is immediate Break out of the loop, that is, no longer execute all subsequent loops; the function of the

continue statement is to stop the executing loop and directly enter the next loop.

计算1+2+3 ... +98+99+100的值var total=0;
<html>
<head>
<meta charset="utf-8">
<title>计算1+2+3 ... +98+99+100的值</title>
</head>
<body>
<script language="JavaScript" type="text/javascript">
var total=0;
for(var i=1; ;i++){ 
 if(i>100){ 
 break; 
 } 
 total+=i; 
 continue; 
 alert(i);
 }
 alert(total);
 </script>
 </body>
 </html>
Continuing Learning
||
<html> <head> <meta charset="utf-8"> <title>计算1+2+3 ... +98+99+100的值</title> </head> <body> <script language="JavaScript" type="text/javascript"> var total=0; for(var i=1; ;i++){ if(i>100){ break; } total+=i; continue; alert(i); } alert(total); </script> </body> </html>
submitReset Code