Structure: 1. The order in accordance with the order an execution of a code, from top to bottom,
2. The code is executed, can choose according to the conditions, conditions of the corresponding results, the more the more branches,
For example:
The if... The else... Statement: if statements behind to the else statement, when the Boolean expression values of if statements to false, the else block can be executed,
Var a=7.
Var b=6;
If (aAlert (" a less than b ");
} else {
Alert (" not less than b ");
}
Switch statement: statement judge whether a value in a variable and a set of values, each value is called a branch,
Var a=100;
Var b=99;
The switch (a> B) {
Case a
break;
In case a=b:
Alert (" a equals b ");
break;
Default:
Alert (" a greater than b ");
Note: the switch must be given initial values, value with each case matching, meet all of the statements that execute the case after using break statement to stop running the next case, such as all case values do not match, execute the statement after the default,
3. The loop structure: to repeat constantly do a thing,
For example, the for loop
For (var I=10; I<20; I++) {
Var a=I * 6;
console.log(a);
}
While loop: as long as the Boolean expression is true, circulation has been implemented,
Var a=20.
While (a<30) {
Var b=a + 1;
+;
console.log(b);
}
The do... While loop: for while statement, if does not meet the conditions, is can't go into circulation, but sometimes we even if does not meet the conditions, also performed at least once, the do... The while loop and the while loop, the difference is that the do... The while loop is executed at least once,
Var a=100;
Do {
Var=a/2 b;
A -;
console.log(b);
} while (a> 2);
CodePudding user response:
Here is the BBS blog at blog.csdn.net