Use the break statement to stop the loop at 5. - Javascript Statement

Javascript examples for Statement:Quiz

Description

Use the break statement to stop the loop at 5.

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

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

<script>
var text = "";
var i;/*from   w  w  w .j  av a  2 s.  c  o  m*/
for (i = 1; i < 10; i++) {
    if (i === 5)
       break;
    document.getElementById("demo").innerHTML += i + "<br>";
}
</script>

</body>
</html>

Related Tutorials