break: 结束本层循环,进入下层循环
return: 两层循环都结束
continue:结束本次循环,开始下次循环
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <p>该实例中,break 语句用在了引用标签"Loop2"上。在 j 等于 12 时,break 语句用于跳出 Loop2 循环。</p> <button onclick="myFunction()">点我</button> <p id="demo"></p> <script> function myFunction() { var text = ""; var i, j; Loop1: // 第一个引用标签 "Loop1" for (i = 0; i < 3; i++) { debugger text += "<br>" + "i = " + i + ", j = "; Loop2: // 第二个引用标签 "Loop2" for (j = 10; j < 15; j++) { if (j == 12) { debugger return } document.getElementById("demo").innerHTML = text += j + " "; } } } </script> </body> </html>
标签:return,text,break,continue,Loop2,循环 From: https://www.cnblogs.com/harryzong/p/17026572.html