Skip to content

Latest commit

 

History

History
36 lines (23 loc) · 974 Bytes

README.md

File metadata and controls

36 lines (23 loc) · 974 Bytes

11. Loops and iteration

Repeat work while controlling termination.

Learn

  • for
  • while
  • for...of
  • break
  • continue

How it works

A for loop is useful when an index matters; for...of reads iterable values directly; while repeats until a condition changes. Every loop needs a clear stopping condition. Array methods can express transformations more clearly than manual mutation.

Common mistake

A loop that never updates its condition can run forever and freeze the page.

Guided challenge

Sum a list with a loop, skip invalid values, and compare with reduce later.

Run the example

Open example.html in a browser and edit example.js. Save, refresh, and use the Console and debugger to inspect values.

Completion check

  • Explain the core idea in your own words without reading the code.
  • Change one input and predict the output before running it.
  • Test one boundary or failure case, then record what you changed.