// program to print the value of i
for (let i = 1; i <= 5; i++) {
// break condition
if (i == 3) {
break;
}
console.log(i);
}
//break keyword, it breaks out of the switch block
//or from the loop.
break keyword, it breaks out of the switch block
switch(expression) {
case x:
// code block
break;
case y:
// code block
break;
default:
// code block
}
//breaking from loop
for(let i=0;i<=100:i++){
console.log(i)
if(i===40){
console.log('Hey you hit 400!');
break;
}
}
//output i from 1 to 40 and at last Hey you hit 400!
if (qChanged == "+") {
console.log("Quantity Incremented");
return;
//use return to break the loop
} else if (qChanged == "-");
{
console.log("Quantity Decremented");
}
for (let i = 1; i <= 10; i++) {
console.log(i);
if (i == 5) {
break;
}
}
var myArray = [22,34,5,67,99,0];
var hasValueLessThanTen = myArray.some(function (val) {
return val < 10;
console.log(val)
});