ป้ายกำกับสามารถใช้เพื่อดำเนินการต่อคำสั่งเพื่อควบคุมโฟลว์ได้แม่นยำยิ่งขึ้นใน JavaScript ป้ายกำกับเป็นเพียงตัวระบุตามด้วยโคลอน (:) ที่ใช้กับคำสั่งหรือบล็อกของโค้ด
ตัวอย่าง
คุณสามารถลองเรียกใช้โค้ดต่อไปนี้เพื่อเรียนรู้วิธีทำงานกับป้ายกำกับด้วยคำสั่ง Continue
การสาธิตสด
<html>
<body>
<script>
document.write("Entering the loop!<br /> ");
outerloop: // This is the label name
for (var i = 0; i < 3; i++) {
document.write("Outerloop: " + i + "<br />");
for (var j = 0; j < 5; j++) {
if (j == 3) {
continue outerloop;
}
document.write("Innerloop: " + j + "<br />");
}
}
document.write("Exiting the loop!<br /> ");
</script>
</body>
</html>