运行 ❯
获取您
自己
的网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <body> <h1>JavaScript Statements</h1> <h2>The break Statement</h2> <p>When i equals 12 in Loop2, the break statement "jumps out" of Loop1.</p> <p id="demo"></p> <script> let text = ""; // The first for loop is labeled Loop1: Loop1: for (let i = 0; i < 3; i++) { text += i + "<br>"; // The second for loop is labeled Loop2: Loop2: for (let i = 10; i < 15; i++) { text += i + "<br>"; if (i === 12) break Loop1; } } document.getElementById("demo").innerHTML = text; </script> </body> </html>