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