javascript
javascript
Loops in Javascript
Live
bolt
Level1
Progress0%

Loops in Javascript

CARD 1

Introduction

Login to report note issues for this section.

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.