Sunday, 24 July 2016

JavaScript break, continue Statement

Jump Statement
It allows us to skip certain statement or jump out of statement.

There are two type of jump statement

  • break statement
  • continue statement
break statement
break statement allows us to break or exit out of loop. It causes loop to immediately exited. If the loops has statements after the break statement, those statement are not executed.
Example

<!DOCTYPE html>
<html>
<head>
    <title>javaScript break statement</title>
</head>
<body>
    <h1>JavaScript break statement</h1>
    <script>
        var number1 = 4;
        while (number1 > 0)
        {
            document.write("count : " + number1 + "<br/>");
            number1--;
            break;
            document.write("statement will not get executed");
        }
    </script>
</body>
</html>


continue statement
continue statement is also used to stop the execution of a loop. However, the continue statement does not exit the loop; it executes the condition for the next iteration of the loop.If the loops has statements after the continue statement, those statement are not executed.
Example

<!DOCTYPE html>
<html>
<head>
    <title>javaScript continue statement</title>
</head>
<body>
    <h1>JavaScript continue statement</h1>
    <script>
        var number1 = 4;
        while (number1 > 0)
        {
            document.write("count : " + number1 + "<br/>");
            number1--;
            continue;
            document.write("statement will not get executed");
        }
    </script>
</body>
</html>

0 comments:

Post a Comment