1. branch statement syntax
A, if statements
if (conditional expression) {
Statement body;
}
execution flow:
If the condition expression evaluates to true, the statement is executed bodies
if the conditional expression is false, the statement does not execute body
if (conditional expression) {
Statement 1;
}else{
Statement 2;
}
Implementation process:
If the condition expression evaluates to true, the statement is executed 1
If the value of Conditional Expression fales, execute the statement 2
if (conditional expression 1) {
Statement 1;
} Else if (conditional expression 2) {
Statement 2;
} Else if (conditional expression n ...) {
Statement body n;
}else{
Body statement n + 1;
}
Implementation process:
Which set up a conditional expression, executes the corresponding statement body,
If the conditional expression is not true, execute statement last else in the body
Two, switch statements
switch (expression) {
Case 1 constant:
statement to be executed 1;
BREAK;
Case 2 constants:
statement to execute 2;
BREAK;
Case 3 Constant:
statement to execute 3;
BREAK;
default:
default statement is to be executed;
BREAK;
}
The implementation process: the expression, the constants and the back of the case and compare which case the same constants, which follows the case on the implementation of the program encountered break, on the whole end
2. loop syntax
for loop
for (initialization expression; conditional expression; expression control condition) {
loop body;
}
execution flow:
1, initialization expression; only performed once
2, the conditional expression
if the result is true, the loop body is executed
if the result is false , the end of the cycle
3, when the loop execution, execution control Conditional expression
4, then, back to the next, until the conditional expression is false end loop
while loop
Initialization expression;
the while (conditional expression) {
statement body;
controlling conditional expression;
}
Execution flow;
1, initialization expression;
2, the conditional expression
if the result is true, the statement is executed bodies
If the result is flase, the end of cycle
3, when the statement is the bank execution, execution control Conditional Expression
4, then, back to the first two-step, until the end of the conditional expression is false loop jump statements (break, continue)
do while loop
Initialization expression;
do {
statement body;
controlling conditional expression;
} the while (conditional expression);
execution flow:
1, initialization expression;
2, execute the statement body
3, control is performed conditional expression
4, the implementation of the conditional expression,
If the result is true, continue seeing the body
if the result is false, the end of the cycle