

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to break a loop in JavaScript?
The break statement is used to break a loop and continue executing the code, which is after the loop.
Example
You can try to run the following code to break a loop in JavaScript
<!DOCTYPE html> <html> <body> <p id="test"></p> <script> var text = ""; var i; for (i = 0; i < 5; i++) { if (i === 2) { break; } text += "Value: " + i + "<br>"; } document.getElementById("test").innerHTML = text; </script> </body> </html>
Output
Value: 0 Value: 1
- Related Questions & Answers
- How to break a for loop in Python?
- How to use the break statement to come out of a loop in JavaScript?
- How to use PowerShell break statement in foreach loop?
- break, continue and label in Java loop
- How to use PowerShell Break statement with the While Loop?
- How to use PowerShell break statement with the For loop?
- How do we use a break statement in while loop in C#?
- How can I break an outer loop with PHP?
- How to create a line break with JavaScript?
- How to control for loop using break and continue statements in C#?
- How do you create a Tkinter GUI stop button to break an infinite loop?
- How to use a line break in array values in JavaScript?
- How to add delay in a loop in JavaScript?
- Finding how many time a specific letter is appearing in the sentence using for loop, break, and continue - JavaScript
- How to implement asynchronous loop in JavaScript?
Advertisements