What types of loops exist in JavaScript?

Experience Level: Junior
Tags: JavaScript

Answer

In JavaScript, there are three types of loops:

  • for loop
  • while loop
  • do...while loop

Here's an example of how each of these loops could be used:

// for loop example
for (let i = 0; i < 10; i++) {
  console.log(i);
}

// while loop example
let j = 0;
while (j < 10) {
  console.log(j);
  j++;
}

// do...while loop example
let k = 0;
do {
  console.log(k);
  k++;
} while (k < 10);

Comments

No Comments Yet.
Be the first to tell us what you think.

Chat

Oh, the operator is not available. Leave us your comments. We will answer all your questions as soon as possible.

Comments

Anonymous
Καλησπέρα.
Anonymous
the infinteis -3/15 so 1triition / infinet
Anonymous
e
Anonymous
<a href="https://inspirum.pl "
Anonymous
[url]https://inspirum.pl[/url]
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e