Monday, 27 August 2018

JavaScript: continue statement

continue statement skips the current iteration of a for, while, do-while loops.

continue.html
<!DOCTYPE html>

<html>

<head>
    <title>continue statement</title>
</head>

<body>
    <script type="text/javascript">
        var number = parseInt(prompt("Enter a number less than 100", "10"));

        document.write("<h2>Even numbers from 0 to " + number + " are </h2>");

        var i = 0;

        while (i <= number) {
            if ((i % 4) == 0) {
                i += 2;
                continue;
            }
            document.write(i + "<br />");
            i += 2;
        }
    </script>
</body>

</html>

Load above page in browser, it prompts for a number and prints all even numbers up to the number, which are not divisible by 4.





Previous                                                 Next                                                 Home

No comments:

Post a Comment