Back to all posts

Loops and iteration


Loops offer a quick and easy way to do something repeatedly.

Loop and iterations are used to execute a block of code repeatedly or iterate over a collection of elements. There are several types of loops available in JavaScript, including far loops, while loops, and do-while loops. Each loop type has its own syntax and use cases.

Syntax

for (initialization; condition; increment/decrement) {
  // code to be executed
}

Example

for (let i = 1; i <= 5; i++) {
  console.log(i);
}

The statements for loops provided in JavaScript are