Control Flow: Conditionals and Loops
Control flow allows you to dictate how your code executes based on certain conditions.
Conditionals:
if
/else if
/else
if (age >= 18) {
console.log('Adult');
} else {
console.log('Minor');
}
switch
statement – alternative to multipleif
-else
blocks.
Loops:
for
while
do...while
for (let i = 0; i < 5; i++) {
console.log(i);
}
break
and continue
can be used to control loop execution.