Skip to main content

Loops: for, while, for...of and for...in

Learn Loops: for, while, for...of and for...in (Phase 2 · Conditions, Loops, Functions (Essential), JavaScript) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.

Repeating work • for (init; test; update) is the classic counted loop; while tests before each pass; do...while runs at least once. • for...of iterates the values of any iterable (arrays, strings, Maps, Sets). • for...in iterates the enumerable keys of an object. Do not use it on arrays. • break leaves the loop; continue skips to the next pass.

More lessons in Phase 2 · Conditions, Loops, Functions (Essential)