JavaScript Loops - Exercise 3

The continue statement in a loop is used to skip the rest of the current iteration and continue to the next iteration of the loop.

The break statement in a loop is used to exit the loop prematurely based on a certain condition, regardless of whether the loop condition is true or false.

The default case in a switch statement is executed when none of the other cases match the expression being evaluated.

The for...of loop in JavaScript is used to iterate over iterable objects like arrays, strings, maps, sets, etc. The syntax is:

javascript

for (const item of iterable) {
    // Code block to be executed
}

You can use a for...of loop in JavaScript to iterate over elements of an iterable object such as arrays, strings, maps, sets, etc.

javascript

const fruits = ['apple', 'banana', 'cherry'];
for (const fruit of fruits) {
    console.log(fruit);
}

A nested switch statement in JavaScript allows you to evaluate multiple expressions and execute corresponding case blocks based on the values of those expressions.

You can use a nested switch statement in JavaScript by placing one switch statement inside another switch statement. This allows you to handle multiple conditions and execute corresponding blocks of code based on the values of those conditions.

javascript

let fruit = "apple";
let color = "red";

switch (fruit) {
    case "apple":
        switch (color) {
            case "red":
                console.log("It's a red apple");
                break;
            case "green":
                console.log("It's a green apple");
                break;
            default:
                console.log("Unknown color for apple");
        }
        break;
    default:
        console.log("Unknown fruit");
}

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.

The break statement in a switch statement is used to exit the switch statement and continue execution at the next statement following the switch.

A switch statement in JavaScript is used to perform different actions based on different conditions.