JavaScript Loops - Exercise 5
In a labeled loop, the break statement is used to terminate the loop identified by the label, allowing you to exit from nested loops or specific outer loops.
The continue statement in a labeled loop allows you to skip the current iteration of the loop identified by the label and continue with the next iteration.
An infinite loop is a loop that continues to execute indefinitely because the loop condition never evaluates to false, resulting in the program getting stuck and becoming unresponsive.
To prevent an infinite loop, ensure that the loop condition will eventually evaluate to false or use a mechanism such as a break statement to exit the loop when a certain condition is met.
The continue statement in a loop is used to skip the current iteration and proceed to the next iteration of the loop without executing the remaining code in the current iteration.
The default case in a switch statement is executed when none of the case expressions match the value of the switch expression. It provides a fallback option for handling unexpected values.
You can use the default case in a switch statement to define the block of code that should be executed when none of the case expressions match the value of the switch expression.
let fruit = "banana";
switch (fruit) {
case "apple":
console.log("Apple is selected");
break;
case "orange":
console.log("Orange is selected");
break;
default:
console.log("Unknown fruit");
}
The fall-through behavior of a switch statement in JavaScript allows the execution to continue to the next case block after the matching case, unless a break statement is encountered.
The break statement in a switch statement is used to exit the switch statement and continue execution at the next statement following the switch.
The continue statement in a switch statement is used to skip the current case and proceed to the evaluation of the next case, if any.