Home > Article > Web Front-end > What are the js loop structures? js loop structure overview
In js, js loop statements are a relatively important part. Many programmers use js loop statements to execute code, but some novices don’t know what js loop structures are? Let's give an overview of the js loop structure.
1: What are the js loop structures?
There are three types of js loop structures, mainly the for statement and the while language, and the other is the do...while statement. [Recommended study: JavaScript Online Manual]
2: Overview of js loop structure
1. The while statement is also a judgment of conditions. The syntax is:
while(条件表达式语句) { 执行语句块; }
while statement and do...while structure diagram:
When the return value of our usage condition is true, the curly brackets will be executed When the statement in the curly brackets is executed, if a value is returned, the statement in the curly brackets will be repeated until the return value is false, the entire process will not end, and then the following code program will be executed.
But when using a while statement, the brackets must use curly brackets. In fact, another disadvantage is that if there are no conditions, it will continue endlessly, which may cause the browser to crash.
2. The do...while statement is actually very similar to the while statement. The only difference is that while first judges the condition and then executes it, while the do...while statement loops once and then judges the condition.
Syntax:
do { 执行语句块; } while(条件表达式语句);
do...while will not loop according to the conditions. If the conditions are met, the loop will be executed. If the conditions are not met, it will exit directly.
3.for loop:
for is composed of two parts, conditional control and loop body.
Grammar:
for(初始化表达式;循环条件表达式;循环后的操作表达式) { 执行语句块; }
Before using for, you must first set a counter, or you can define it before for. In the grammar, the initialization expression represents the initial value, and the loop expression is Counter first variable.
The above is what are the js loop structures? A complete introduction to the overview of js loop structure. If you want to know more about JavaScript tutorial, please pay attention to the php Chinese website.
The above is the detailed content of What are the js loop structures? js loop structure overview. For more information, please follow other related articles on the PHP Chinese website!