javascript
Loops in JavascriptjavascriptLevel1
Progress0%
Contents
Loops in Javascript
1 / 12
Introduction
Loops — for, while, do-while
A loop is a control structure that repeats a block of code multiple times until a specified condition becomes false. Instead of writing the same code repeatedly, a loop handles repetition automatically.
Without loops:
codejs
1console.log(1);
2console.log(2);
3console.log(3);
4console.log(4);
5console.log(5);With a loop:
codejs
1for (let i = 1; i <= 5; i++) {
2 console.log(i);
3}JavaScript has three primary loop types: for, while, and do-while.