Repeat work while controlling termination.
- for
- while
- for...of
- break
- continue
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.
A loop that never updates its condition can run forever and freeze the page.
Sum a list with a loop, skip invalid values, and compare with reduce later.
Open example.html in a browser and edit example.js. Save, refresh, and use the Console and debugger to inspect values.
- 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.