JavaScript Process Control
Process: is the execution order of the program code.
Process Control: The program code is conditionally executed in a certain way through the prescribed statements.
First, sequential structure
Execution in the order of writing is the most basic process structure in the program.
II. selection structure (branching structure, conditional structure)
The corresponding statement of the selected execution shape according to the given condition.
(1) If else if else
1. Single-channel branch
The condition can either be an expression or any data type
Curly braces will run the code inside of him as a whole, and if there is only one statement, you can omit the curly brace
if (condition) {
Statement of conditional execution
}
2. Two-way Branch
if (condition) {
Code executed when the condition is set
}else{
Code that executes when the condition is not established
}
3. Multi-Channel Branch
if (condition 1) {
Condition 1 The code of execution is established
}elseif (condition 2) {
Condition 2 The code of execution is established
}elseif (condition 3) {
Condition 3 The code of execution is established
}......else{
If the above conditions do not establish the code of execution
}
4. Nesting branches
if (condition 1) {
if () {
}elseif () {
}....
}elseif (condition 2) {
Condition 2 The code of execution is established
}elseif (condition 3) {
Condition 3 The code of execution is established
}......else{
If the above conditions do not establish the code of execution
}
(2)
switch (any data type of the variable) {
Case value 1:
Expression 1;
Break
Case Value 2:
Expression 3;
Break
.........
Defalut:
An expression
}
Multiple selections to match accordingly
*************************************************
1. It is best to use an if statement when judging a range, and switch when judging a single value
2. Conditions can not be repeated, unexpected errors occur.
*************************************************
Third, the cycle structure
JavaScript Learning notes--javascript Process Control