Lesson content
Read, practise, then check your understanding
Use classic for for indexed counting, while for condition-driven repetition, and do...while when the body must run once.
Values versus keys
const values = [2, 4, 6];
for (const value of values) {
console.log(value);
}
const record = { name: "Mira", score: 90 };
for (const key of Object.keys(record)) {
console.log(key, record[key]);
}
for...of consumes iterable values. for...in enumerates enumerable string keys, including inherited ones, so avoid it for arrays and guard object ownership when needed. break exits and continue advances. Verify termination and complexity; array methods often express transformations more clearly than manual loops.
Knowledge check
Answer every question correctly to complete this chapter.
0 of 10 checks passed
Your progress is saved on this device.