Hackforge Academy

Category: javascript

loops

Published on 29 Jun 2026

Explanation

Loops execute a block of code repeatedly until a specified condition is met.

Code:

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

Explanation

The while loop continues executing as long as its condition remains true.

Code:

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

Explanation

The do...while loop executes the code at least once before checking the condition.

Code:

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

Explanation

The for...of loop iterates over arrays and other iterable objects.

Code:

const colors = ['Red', 'Blue'];
for (const color of colors) {
  console.log(color);
}

Explanation

The break statement exits a loop early, while continue skips the current iteration.

Code:

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

๐Ÿš€ Learn Spring Boot with real-world projects

๐Ÿ’ก Build REST APIs step by step

๐Ÿง  Improve backend development skills

๐ŸŽฏ Get career-ready practical training

Join Our Free WhatsApp Community

Direct access to niche-specific mentors and peers on WhatsApp.

๐Ÿ

Python Community

Discuss Django, FastAPI, AI integration, and automation scripts with 15k+ developers.

Join Python Community
โš›๏ธ

React Community

Master Next.js, Framer Motion, and State Management. Share your latest UI components.

Join React Community
โ˜•

Java Community

Deep dives into Spring Boot, Microservices architecture, and high-performance backend ops.

Join Java Community