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
  1. 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, an HTML file.
 
Step 3
 
The code of the continue statement program:
 
ExampleOfContinue.ts
  1. class ExOfContinue {  
  2.  MyFunction() {  
  3.   for (var n = 1; n <= 10; n++) {  
  4.    if (n % 4 == 0)  
  5.     continue;  
  6.    var y = document.createElement("y");  
  7.    y.innerText = n.toString();  
  8.    y.innerText = "" + n + "\n";  
  9.    document.body.appendChild(y);  
  10.   }  
  11.  }  
  12. }  
  13. window.onload = () => {  
  14.  var value = new ExOfContinue();  
  15.  value.MyFunction();  
  16. }  
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 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
  1. <!DOCTYPEhtml>  
  2. <htmllang="en"  
  3.     xmlns="http://www.w3.org/1999/xhtml">  
  4.     <head>  
  5.         <metacharset="utf-8"/>  
  6.         <title>TypeScript HTML App</title>  
  7.         <linkrel="stylesheet"href="app.css"type="text/css"/>  
  8.         <scriptsrc="app.js">  
  9.         </script>  
  10.     </head>  
  11.     <body>  
  12.         <h1>Value between 1 to 10 Without multiple of 4(four)</h1>  
  13.         <divid="content"/>  
  14.     </body>  
  15. </html>  
app.js
  1. var ExOfContinue = (function() {  
  2.  function ExOfContinue() {}  
  3.  ExOfContinue.prototype.MyFunction = function() {  
  4.   for (var n = 1; n <= 10; n++) {  
  5.    if (n % 4 == 0) {  
  6.     continue;  
  7.    }  
  8.    var y = document.createElement("y");  
  9.    y.innerText = n.toString();  
  10.    y.innerText = "" + n + "\n";  
  11.    document.body.appendChild(y);  
  12.   }  
  13.  };  
  14.  return ExOfContinue;  
  15. })();  
  16. window.onload = function() {  
  17.  var value = new ExOfContinue();  
  18.  value.MyFunction();  
  19. };  
Output
 
continue-statement-in-typescript.jpg


Similar Articles