JavaScript Tutorial
JS - Introduction JS - Basic JS - Placement JS - Output JS - Statements JS - Syntax JS - Variables JS - Comments JS - Data Types JS - Operators JS - Operator Precedence JS - Condition JS - Switch JS - Functions JS - Objects JS - Loops For JS - Loops While JS - Break JS - Strings JS - String Methods JS - Numbers JS - Number Methods JS - Arrays JS - Array Methods JS - Array Iteration JS - Events JS - Event Listener JS - Event Propagation JS - Date JS - Math JS - Random JS - Boolean JS - Type Conversion JS - RegExp JS - Exception JS - Scope JS - Debugging JS - Hoisting JS - Strict Mode JS - this Keyword JS - Mistakes JS - Best Practices JS - Performance JS - Form Validation JS - ES6 Features
JS Objects
Object Definitions Object Properties Object Methods Object Constructors Object Prototypes
JS Functions
Function Definitions Function Parameters Function Call Function Apply Function Closures
JS HTML DOM
DOM Introduction DOM Methods DOM Selectors DOM HTML DOM CSS DOM Attributes DOM Navigation
JS Browser BOM
JS - Window JS - Screen JS - Location JS - History JS - Navigator JS - Popup Alert JS - Timing JS - Cookies
JS AJAX
AJAX - Introduction AJAX - XMLHttp AJAX - Request AJAX - Response AJAX - PHP
JS JSON
JSON - Introduction JSON - Syntax JSON - Data Types JSON - Parse JSON - Stringify JSON - Objects JSON - Arrays JSON - PHP JSON - JSONP
JS References
JavaScript Reference JavaScript Methods HTML DOM Reference

JavaScript Break and Continue

The break statement "jump out" of a loop.

The continue statement skip one iteration and start the next iteration of the loop.


The break Statement

The break statement terminates the current loop, switch, or label statement and transfers program control to the statement following the terminated statement.

When the break statement is used in a loop, it breaks the loop and continues executing the code after the loop.

Run code

When the break statement is used with a switch statement, it breaks out of the switch block. This will stop the execution of more execution of code and/or case testing inside the block.

Run code

The continue Statement

The continue statement terminates execution of the statements in the current iteration, and continues execution of the loop with the next iteration.

The following example shows a for loop that has a continue statement that executes when the value of i is 3:

Run code

The following example shows a while loop that has a continue statement that executes when the value of i is 3:

Run code

JavaScript Labels

A label is simply an identifier followed by a colon (:) that is applied to a statement or a block of code.

label:
statements

The break statement, can be used to "jump out" of a loop, a switch or a label statement.

break labelname;

The following code uses break statements with labeled blocks, to "jump out" of a JavaScript code block:

Run code