 
 Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP 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
Advertisements
                    