Home/Tutorials/JavaScript/Loops: for and while

0 of 3 saved

JavaScript5 min read

Loops: for and while

Read this chapter, write the program on this page, then pass a short check to open the next one.

Repeat work safely.

Loops: for and while

for and while repeat until a condition fails. Prefer for...of for arrays when you need values.

  • for (let i = 0; i < n; i++) is classic indexing.
  • for...of iterates values; for...in iterates keys (use carefully).
  • break exits early; continue skips one iteration.
let sum = 0;
for (let i = 1; i <= 3; i++) sum += i;
console.log(sum);

After you read this chapter, use Write (when available) and Quiz on this page to lock it in.