
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
How to use the break statement to come out of a loop in JavaScript?
The break statement is used to exit a loop early, breaking out of the enclosing curly braces.
Example
You can try to run the following code to learn how to use the break statement to come out of a loop
<html> <body> <script> var x = 1; document.write("Entering the loop<br /> "); while (x < 20) { if (x == 5) { break; // breaks out of loop completely } x = x + 1; document.write( x + "<br />"); } document.write("Exiting the loop!<br /> "); </script> </body> </html>
- Related Articles
- How to use PowerShell break statement in foreach loop?
- How to use PowerShell Break statement with the While Loop?
- How to use PowerShell break statement with the For loop?
- How to break out of a loop in Perl?
- How to break a loop in JavaScript?
- How do we use a break statement in while loop in C#?
- How to come out of a switch case in JavaScript?
- How can I use a label with break statement in JavaScript?
- How to use for...in statement to loop through an Array in JavaScript?
- How to use continue statement in Python loop?
- How we can come out of an infinite loop in Python?
- How to use PowerShell Break statement with the Switch command?
- What is a break statement in Java and how to use it?
- How to break a for loop in Python?
- How to use a line break in array values in JavaScript?

Advertisements