The difference between break and continue in JavaScript
break statement and continue statement
##break statement
- Description: break statement, used to unconditionally end various loops (exit the loop) and switch.
- Note: Generally, you need to add a conditional judgment before the break statement. In other words: when the condition is established, the loop exits.
##continue statement
- Description: End this cycle and start the next cycle. The code after continue is no longer executed.
- Note: Generally, you need to add a conditional judgment before the continue statement.
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>php.cn</title> <script> var sum = 0; for(var i=1;i<=10;i++){ if(i==6){ break; // continue; } document.write(i+" "); } </script> </head> <body> </body> </html>