JavaScript note five

  

1. The conditional branch statement
- Switch statement
- Syntax:
Switch (conditional expression) {
Case expression:
statement ...
BREAK;
Case expression:
statement ...
BREAK;
Case expression:
statement ...
BREAK;
default:
statement ...
BREAK;
}

- execution flow:
- switch ... case ... statement is executed, will be followed by the value of the expression of the value of the switch expression and the case be congruent comparison,
if the comparison the result is false, the comparison continues downward. If the comparison is true, from the current case at the beginning of the implementation of the code down.
If all of the case are the result of judgment is false, from default at the beginning of the implementation of the code.

2. loop
- to perform certain statements many times through loop repeatedly
- while cycling
- Grammar:
the while (conditional expression) {
statements ...
}

- the flow of execution:
the while statement is executed, will first of conditional expression evaluated determination,
if the determination result is false, then the loop is terminated
if the determination result is true, the loop body is executed
Loop is finished, continued determination condition expression is evaluated, and so on

- do ... while loop
- Syntax:
do {
statement ...
} the while (conditional expression)

- execution flow
do ... while in when executed, the first iteration of the loop do, then the conditional expression of judgment,
if the determination result of the determination is false, the loop ends.
If the determination is true, the loop continues, and so on

- and while the difference:
the implementation of the first judgment: while
do ... while: After performing the first judgment
- do ... while loop ensures that at least once .


- for loop
- Syntax:
for (initialization expression ①; ② conditional expression; ④ updating expression) {
③ statement ...
}
- execution flow:
firstly performs initialization expression ①, initialize a variable,
then the condition ② Expression determining the formula is evaluated, if the loop ends is false
if the determination result is true, the loop is executed ③
loop is finished, perform updating expression ④, the variables are updated.
Repeat finished updating expression ②

- death cycle
the while (to true) {

}

for (;;) {

}

 

Guess you like

Origin www.cnblogs.com/Jiang-jiang936098227/p/11595437.html