Do While Loop in Typescript

Do While Loop in Typescript

In this post, we are going to checkout Do while loop with examples in typescript. Do while Loop in Typescript is same as the Do While Loop in Javascript

Do While Loop in Typescript

Do while loop is the same as a [while loop]

While loop executes the condition expression first.

Do while loop executes the condition expression last after the code statement executes.

Do and while are keywords in typescript. In this do-while loop, Code statements execute at least once.


Syntax of Do while loop is as below.

do{  
// code block statements  
}  
while(Conditional Expression)  


If the conditional expression is true, code block statements re-execute.

Example of Do While Loop is as below.

let counter=1;   
do {  
    console.log(counter)  
    counter++;    
}  
while (counter <= 5) 

Output:

1  
2  
3  
4  
5  


The above example prints the number from 1 to 5.

πŸ”₯ 2 Views
Sep 2, 2022