Use a while loop together with the continue statement. - Javascript Statement

Javascript examples for Statement:while

Description

Use a while loop together with the continue statement.

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">Test</button>

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

<script>
function myFunction() {// www.  j  a v a2s. com
    var text = "";
    var i = 0;
    while (i < 5) {
        i++;
        if (i === 3) {
            continue;
        }
    text += "<br>The number is " + i;
    }
    document.getElementById("demo").innerHTML = text;
}
</script>

</body>
</html>

Related Tutorials