let numbers = [2, 3, 5, 7, 11, 13, 17, 19];
let str = "";
for (let i = 0; i < numbers.length; i++) {
if (numbers[i] > 10)
break;
str += (str === "" ? "" : "-") + numbers[i];
}
//str is "2-3-5-7"
console.log(`str is "${str}"`);
| Use the break statement to terminate a loop, switch, or in conjunction with a labeled statement. - When you use break without a label, it terminates the innermost enclosing while, do-while, for, or switch immediately and transfers control to the following statement. - When you use break with a label, it terminates the specified labeled statement. |