Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use JavaScript flow Control statement

Shulou Source: shulou.com Published: 2022-06-01 10:32:16 10月13日 Update

This article mainly introduces the relevant knowledge of "how to use JavaScript process control statements". The editor shows you the operation process through an actual case. The operation method is simple, fast and practical. I hope this article "how to use JavaScript process control statements" can help you solve the problem.

1. Introduce

Through the study of the last course, we can use the conditional structure to implement the selective execution of the code, so what should we do if we need to execute multiple times when implementing the requirements? At this point, we can use the loop structure to implement our code function.

two。 Cyclic structure

If you need to run the code multiple times and use different values each time, loop is quite convenient to use. There are three main loops in JavaScript: for loop, while loop and do-while loop. So let's explain the operation of each loop one by one.

3.for cycle

(1) .for recycling scenarios

For loop, because it can control the number of times and subscripts, it is generally used when you already know the number of loops and when you need to subscript the number of loops.

(2) the syntax and content description of the .for loop

For loop syntax and related structures

For (statement 1; statement 2; statement 3) {

Block of code to be executed

}

Detailed explanation of parameters

Statement 1 is executed before the loop (code block) begins. Commonly used to define initialization subscript

Statement 2 defines the conditions under which the loop (code block) is run. It is usually a conditional statement that states whether the relevant block of code needs to be executed again.

Statement 3 is executed each time the loop (code block) is executed. It is generally an incremental statement, which controls the number of increments, and the number of times the statement forms a loop

A standard for loop code:

For (var iTuno Bandi)

Tags: Loop code statement condition syntax control times content time structure process subscript scenario knowledge difference increment odd situation effect industry Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Redmi Xiaomi MariaDB Apple