Break Statement in Do While Loop

Break Statement in Do While Loop

In this post, we are going to checkout how to use Break Statement in Do while loop with examples in typescript. Do while Loop in Typescript is same as the Do While Loop in Javascript. Break Statement help to break out of the current Loop.

The break is a keyword in typescript. It is used to exit from the loop execution. In a loop, it breaks out of the loop and continues executing the code after the loop (if any).

Further statements after the keyword break are not executed in any loop or switch cases.

Syntax :

break;  


Break out of Loop using Break statement Here is an example

let counter=1;   
do {    
    if (counter % 3 == 0) {  
        console.log("If Condition met")  
        break  //Do While loop will exit here for first matched number divided by 3 is zero  
    }  
    counter++;  
    console.log("condition not met")  
}  
while (counter <= 5) 


The result of Break statement example is as follow

condition not met  
condition not met  
IF Condition met  


Happy Coding!


πŸ”₯ 3 Views
Sep 2, 2022