// program to print the value of i
for (let i = 1; i <= 5; i++) {
// break condition
if (i == 3) {
break;
}
console.log(i);
}
// The break statement breaks out of a switch or a loop.
let text = "";
for (let i = 0; i < 5; i++) {
if (i == 3) break;
text += i;
}
// output: 012
breakme: if (condition) {
// Do stuff
if (condition2){
// do stuff
} else {
break breakme;
}
// Do more stuff
}
for (let i = 1; i <= 10; i++) {
console.log(i);
if (i == 5) {
break;
}
}