loops

Types of Loops in JavaScript

  • Profile picture of Mcs
  • by Mcs June 30, 2025

In JavaScript, a loop is a control structure that allows for the repeated execution of a block of code until a specified condition is met. Loops are fundamental for automating repetitive tasks and processing collections of data efficiently, avoiding the need to write the same code multiple times.

There are several types of loops in JavaScript:

1. for loop

Used when the number of repetitions is known.
 

for loop

2. while loop

Repeats while a condition is true.

while loop

3. do...while loop

Runs the code at least once, then repeats while the condition is true.

do while loop

4. for...of loop (used for arrays)

for of loop

5. for...in loop (used for objects)

for in loop

Comments

Add new comment

Restricted HTML

  • Allowed HTML tags: <br> <p> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id> <cite> <dl> <dt> <dd> <a hreflang href> <blockquote cite> <ul type> <ol type start> <strong> <em> <code> <li>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.