Jane_Doe
Mangaka Apprentice
2
MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1
400 XP
- Conditionals allow executing code based on certain conditions
- if/else statements:
- if checks a condition and runs block if true
- else runs if condition is false
- Multi-way decisions with else if
- switch statements:
- Switch on a variable/expression
- Case labels to match values
- Default case catches the rest
- Examples:
if (age >= 18) { // allow vote } else { // too young }
switch(day) { case "Monday": // code here break; default: // default case } - Loops allow repeating code:
- for loop - iterate over arrays, ranges
- while loop - repeat until condition is false
- do-while - run once before checking condition
- Loop examples:
for (let i = 0; i < 5; i++) { // repeats 5 times }
while (count > 0) { // repeats until count = 0 } - Break and continue keywords