Several methods of js loop

There are a variety of loop structures that can be used in JS, such as for loops, while loops, do-while loops, etc. Here are example uses of these loop structures:

  1. for loop:
for(var i = 0; i < 10; i++) {
  console.log(i);
}

  1. while loop:
var i = 0;
while(i < 10) {
  console.log(i);
  i++;
}

  1. do-while loop:
var i = 0;
do {
  console.log(i);
  i++;
} while(i < 10);

These loop structures can be selected and used according to specific needs to implement the function of cyclically executing a certain piece of code.

Guess you like

Origin blog.csdn.net/m0_74265396/article/details/135435530