Day 3: Loops (for, while) & break/continue
Daily Objective
Section titled “Daily Objective”Automate repeated tasks with for and while loops, and use break and continue control keywords.
1. The for Loop
Section titled “1. The for Loop”for (let i = 1; i <= 5; i++) { console.log(`Iteration: ${i}`);}2. The while Loop
Section titled “2. The while Loop”let energy = 3;while (energy > 0) { console.log(`Running... energy: ${energy}`); energy--;}3. break and continue
Section titled “3. break and continue”continue: Skips current iteration and moves to next.break: Immediately terminates the entire loop.
for (let i = 1; i <= 10; i++) { if (i === 3) continue; // skip 3 if (i === 8) break; // stop at 8 console.log(i);}Daily Hands-on Practice (70%)
Section titled “Daily Hands-on Practice (70%)”- Write a loop printing numbers from 1 to 20, skipping multiples of 3 using
continue. - Compute the sum of all numbers between 1 and 100 using a loop.