Home >Web Front-end >Front-end Q&A >What are the loop structures provided by javascript?
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.
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.
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!