The functions of JavaScript flow control statements: 1. Sequential structure, used to execute statements in the order they appear; 2. Conditional structure, used to determine the order of execution according to given logic; 3. Loop structure, used to determine the order of execution according to the code logic Conditions determine whether to repeatedly execute a certain program.
The operating environment of this tutorial: Windows 10 system, JavaScript version 1.8.5, Dell G3 computer.
.Three basic process structures of JavaScript
(1) Sequential structure: statements are executed sequentially in the order in which they appear.
(2) Conditional structure: Determine the execution order according to the given logic. It can be divided into single, double and multiple choices. The more corresponding conditions, the more code options are available.
(3) Loop structure: Determine whether to repeatedly execute a certain program based on code logic conditions. If the return value of the logical condition is true, the loop will be entered, otherwise the loop statement will not be executed.
JavaScript conditional control statements
·The if statement is a relatively simple selection structure. If the given logical conditional expression is true, a given set of statements will be executed.
·The if...else statement determines the logical condition given after if. When the condition is true, the statement in if is executed. When the condition is not true, the code in else is executed.
·if...else if nested statement selects one group among multiple groups of statements to execute
·The switch statement has the same effect as the if...else if...nested statement, but it is more convenient, concise and more readable than the if...else if...nested statement.
3.JavaScript loop control statements
·The for loop statement executes the statements in the loop body a specified number of times if the conditions of the loop statement are met.
·The while loop statement repeatedly executes the statements in the loop body if it meets the conditions of the loop statement.
·The principle of do...while loop statement is the same as that of while loop statement, but it is an execution statement. The code is executed first and then the condition is judged. That is, the loop is executed at least once