Home  >  Article  >  Web Front-end  >  What are the loop structures provided by javascript?

What are the loop structures provided by javascript?

藏色散人
藏色散人Original
2021-11-08 14:33:543309browse

The loop structures provided by JavaScript include: 1. for loop, which traverses the code block multiple times; 2. for/in loop, which traverses the object properties; 3. while loop, which loops through a block of code when the specified condition is true. ; 4. Do/while loop, loops a block of code when the specified condition is true.

What are the loop structures provided by javascript?

The operating environment of this article: windows7 system, javascript version 1.8.5, Dell G3 computer.

What are the loop structures provided by JavaScript?

If you need to run the code multiple times, using different values ​​each time, a loop is very convenient to use.

JavaScript supports different types of loops:

1.for - Traverse a code block multiple times

The syntax of a for loop is as follows:

for (语句 1; 语句 2; 语句 3) {
     要执行的代码块
}

2.for /in - Traverse object properties

Syntax

for (key in object) {
  // code block to be executed
}

3.while - Loop a block of code when the specified condition is true

Syntax

while (条件) {
    要执行的代码块
}

4. do/while - Loop a block of code when the specified condition is true

Syntax

do {
    要执行的代码块
}

while (条件);

For knowledge about javascript loops, please check "javascript loop#" in the javascript manual ##"chapter.

Video tutorial recommendation: "

javascript basic tutorial"

The above is the detailed content of What are the loop structures provided by javascript?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn