Skip to content
Guest
Learn JavaScript · Course Syllabus Show lessons
Language Foundations · 8 min read · Beginner

Loops & Iteration (for...of, for, while)

Iterate over arrays, strings, and ranges cleanly with for...of, classic for loops, break, and continue.

What you'll learn

  • Loop cleanly over arrays and strings with for...of
  • Use classic for loops when you need numeric ranges or step sizes
  • Skip or stop iterations cleanly using continue and break

Loops let your program repeat work without copy-pasting code. In modern JavaScript, for...of is the cleanest default for iterating arrays, strings, Maps, and Sets.

for...of vs. Classic for

const tracks = ['HTML', 'CSS', 'JavaScript'];

for (const track of tracks) {
  console.log(track);
}

Use continue to skip the current item and move to the next, or break to exit the loop early (something .forEach() cannot do!).

Fill-in-the-Blank Exercise

Iterate with for...of and break

Loop through lessons with for...of and stop immediately when you find 'CSS Grid'.

for (const lesson  lessons) {
if (lesson === 'CSS Grid') ;
console.log(lesson);
}

Try It Yourself

Looping & Early Exit with for...of
Live Result
Console Output

No console output yet. Try calling console.log(...) in JS.

Check Your Understanding

Score: 0 / 1

1. Which loop allows you to exit early using the break statement?

Study Workspace

Finished this lesson?

Your progress is saved locally in your browser, no account needed.

Search courses, lessons, and references

Type to search across all courses, lessons, and quick references.

Press Esc to close Powered by Pagefind