#atom
ID: JS-009
Date: [Insert Date]
Content:
Control structures allow you to alter the flow of loops and conditional statements.
break
Statement:
- Exits a loop or
switch
statement immediately.
Example:
for (let i = 0; i < 10; i++) {
if (i === 5) {
break;
}
console.log(i); // 0, 1, 2, 3, 4
}
continue
Statement:
- Skips the current iteration of a loop and continues with the next iteration.
Example:
for (let i = 0; i < 5; i++) {
if (i === 2) {
continue;
}
console.log(i); // 0, 1, 3, 4
}
return
Statement:
- Exits a function and optionally returns a value.
Example:
function add(a, b) {
return a + b;
}
console.log(add(2, 3)); // 5
Connections:
Connections:
Sources: