JavaScript

May 26, 2023

How to use Break Statement in JavaScript Program

Program to use break statement JavaScript Language


let a;
let b = 5;
for (a = 0; a <= 10; a++) {

    if (b == a) {
        break;
    }
    console.log("Number =",a);
}

Output


Number = 0
Number = 1
Number = 2
Number = 3
Number = 4

Steps Description

  1. Declare two variables a and b
  2. Initialize two variables with value of 5 respectively a and b
  3. break statement works with loop
  4. The break statement will break the for loop if the condition in the under if statement of the loop is matched.
  5. console.log inbuild function to display a variable number

by : Suhel Akhtar

Quick Summary:

break statement is used to exit the loop Example 0 to 10 loop runs but break statement causes it to break out of loop and 0 to 4 loop runs