May 26, 2023
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
- Declare two variables
a
andb
- Initialize two variables with value of 5 respectively
a
andb
- break statement works with loop
- The break statement will break the for loop if the condition in the under if statement of the loop is matched.
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