Javatpoint Logo
Javatpoint Logo

TypeScript Indefinite Loops

Loops are the sequence of instructions that is continually repeated until a certain condition is reached. It makes the code compact. It is mostly used in the array. Below is the general structure of loop statement:

TypeScript Indefinite Loops

Loops can be classified into two types:

  1. Indefinite
  2. Definite
TypeScript Indefinite Loops

Indefinite Loop:

In Indefinite loops, the number of iterations is not known before beginning to execute the block of statements. There are two indefinite loops:

  1. while loop
  2. do while loop

TypeScript while loop

The TypeScript while loop iterates the elements for the infinite number of times. It executes the instruction each time the specified condition evaluates to true. It should be used if the number of iteration is not known. The syntax of while loop is given below.

Syntax

TypeScript Indefinite Loops

Example

Output:

The factorial of the given numer is: 24

TypeScript do-while loop

The TypeScript do-while loop iterates the elements for the infinite number of times similar to the while loop except that the code is executed at least once whether the condition is true or false. The syntax of the do while loop is given below.

Syntax

TypeScript Indefinite Loops

Example

Output:

10
11
12
13
14
15




Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


B.Tech / MCA