Loop Control Statement in JavaScript
The Break Statement The break statement can be used to jump out of a loop even when the condition is true. The break statement breaks the loop and continues executing all the code after the loop(if any):
1 2 3 4 5 6 | <script> var i; for(i = 0; i <= 5; i++){ text += "The number is:"+i; } </script> |
OUTPUT
1 2 3 4 5 6 | The number is: 0 The number is: 1 The number is: 2 The number is: 3 The number is: 4 The number is: 5 |
This time though, we want to stop execution of the loop when i become 3. To do so, we are … Read more