Javascript basic tutorial flow control statement
What are the conditional statements?
if statement
if (condition){
Execution code;
}
Example:
javascript
Note: x is equal to 5. Execute the if statement. If x is less than 4, execute the following statement. In this code, x does not meet the conditions, so it will not Execute the following statement, the output is empty;
if...else
if (condition){
Execution code if the condition is met
}else{
Execution code if the condition is not met
}
Example:
javascript
Note: x =5 Determine whether the condition meets x<4 If the condition is true, execute alert('true'); Otherwise, execute alert('false');
if.... .else if....else
if(condition 1){
Execute statement 1
}else if(condition 2){
Execution statement 2
}else if(condition 3){
Execution statement 3
}else{
Does not meet the above Conditional execution statement 4
}
Example:
控制流程语句 if....else if....else
switch statement
##switch (condition) { case 1:Execute statement;break; case 2:Execute statement;break; case 3:Execute statement;break; default :Execution statement; } Example:Note: switch is used in combination with break. When myweek is equal to 1, if there is no break after the execution statement ; Will output all the cases from case 1 to default, plus break. When the conditions are found to be met, no further execution will occur. The switch must have an initial value. When all conditions are not met, the default statement will be executed流程控制语句 switch 语句