Using the break statement with a label reference, to "jump out" of a code block: - Javascript Statement

Javascript examples for Statement:break

Description

Using the break statement with a label reference, to "jump out" of a code block:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<p id="demo"></p>

<script>
var cars = ["a","b","c","d","e"];
var text = "";

list: {//w  ww .  j av a2 s  . c o  m
    text += cars[0] + "<br>";
    text += cars[1] + "<br>";
    text += cars[2] + "<br>";
    break list;
    text += cars[3] + "<br>";
}

document.getElementById("demo").innerHTML = text;
</script>

</body>
</html>

Related Tutorials