Continue Statement in TypeScript

Continue Statement in TypeScript

The continue statement makes the flow of execution skip the rest of a loop body to continue with the next loop. The continue statement is similar to the break in that it stops the execution of the loop at the point it is found, but instead of leaving the loop, it starts execution at the next iteration. The continue statement does not interfere with the number of times the body of the loop is repeated as does the break statement but it only influences the flow of control in any one particular iteration.

Syntax

continue;


Step 1

Open Visual Studio 2012 and click on "File" menu -> "New" -> "Project". After that, a window is opened, enter the name of  your application like "ExampleOfContinue", then click on the Ok button.

Step 2

After Step 1, your project has been created. The Solution Explorer, which is shown on the right side of Visual Studio, contains the js file, ts file, css file and html file.

Step 3

The code of the continue statement program:

ExampleOfContinue.ts

 

class ExOfContinue {

    MyFunction() {

        for (var n = 1; n <= 10; n++) {

             if (n%4==0)

              continue;

                  var y = document.createElement("y");  

                 y.innerText = n.toString();

                 y.innerText = "" + n + "\n";

                 document.body.appendChild(y);            

        }

    }

}

window.onload = () =>{

    var value = new ExOfContinue();

    value.MyFunction();
}


Note In the above declared program, n is declared and initialized to Zero(0). In the for loop, after each iteration, the value of n is incremented by one (1), until the the for loop condition will be true. When n becomes a multiple of four, the continue statement is executed and jumps over the remaining part of the body and back to the loop and updates the value of n by 1 (n++) to begin another iteration.

default.html
 

<!DOCTYPEhtml>

 

<htmllang="en"xmlns="http://www.w3.org/1999/xhtml">

<head>

    <metacharset="utf-8"/>

    <title>TypeScript HTML App</title>

    <linkrel="stylesheet"href="app.css"type="text/css"/>

    <scriptsrc="app.js"></script>

</head>

<body>

    <h1>Value between 1 to 10 Without multiple of 4(four)</h1>

 

    <divid="content"/>

</body>
</
html>


app.js

 

var ExOfContinue = (function () {

    function ExOfContinue() { }

    ExOfContinue.prototype.MyFunction = function () {

        for(var n = 1; n <= 10; n++) {

            if(n % 4 == 0) {

                continue;

            }

            var y = document.createElement("y");

            y.innerText = n.toString();

            y.innerText = "" + n + "\n";

            document.body.appendChild(y);

        }

    };

    return ExOfContinue;

})();

window.onload = function () {

    var value = new ExOfContinue();

    value.MyFunction();

};



Output

continue-statement-in-typescript.jpg

Up Next
    Ebook Download
    View all

    Test

    Read by 16 people
    Download Now!
    Learn
    View all