-
JS Setting Up Environment
-
JS Syntax
-
JS Comments
-
JS Generating OutPut
-
JS Variables
-
JS Data Types
-
JS String
-
JS String Methods & Properties
-
JS Template Literals
-
JS Operators
-
JS Conditional Statements
-
JS Break and Continue
-
JS Functions
-
JS DOM
-
JS DOM Methods and Elements
-
JS DOM HTML/CSS Manipulation
-
JS DOM Navigation & Nodes
-
JS Events
-
JS Array
-
JS Loops
-
JS Object
-
JS Accessors
-
JS Object Constructors
-
JS Prototype & Iterables
-
JS Date & Time Function
-
JS Math Function
-
JS Storage
-
JS Classes
-
JS Map & Set
-
JS Global Scope
-
JS Rest and Spread
-
JS Error Handling
-
JS Asynchronous
-
JS Promise
-
JS Async/Await
-
JS Node.js
-
JS Regular Expression
-
JS Fetch API
-
JS BOM
-
JS Form Validation
-
JS Practiced Example
-
JS Projects
Break and Continue Statement
Break Statement:
The `break` statement in JavaScript is used to terminate a loop prematurely. When encountered, it immediately exits the loop, and the program continues with the next statement after the loop.
Example:
In this example,
The loop will print numbers 1 and 2, then encounter the `break` statement when `i` is 3, and exit the loop.
Continue Statement:
The `continue` statement in JavaScript is used to skip the current iteration of a loop and move on to the next one.
Example:
for (let i = 1; i <= 5; i++) {
if (i === 3) {
continue; // skips iteration when i is 3
}
console.log(i);
}
In this example, the loop will print numbers 1, 2, 4, and 5. When `i` is 3, the `continue` statement is encountered, and the loop skips the rest of the code for that iteration.
The `break` and `continue` statements are useful for controlling the flow of loops and handling specific conditions during their execution.