3.1 Program Flow control
Judging structure
Select structure
Loop structure
3.1.1 Judgment Structure
If statement
Three different formats:
1. if (conditional expression) {
Execute the statement;
}
2. if (conditional expression) {
Execute the statement;
} else {
Execute the statement;
}
3. if (conditional expression) {
Execute the statement;
} else if (conditional expression) {
Execute the statement;
}
......
else{
Execute the statement;
}
If the statement of the control is only one, you can not {}; that is, if the if does not have {}, it only controls the statement closest to it.
3.1.2 Selection structure
Switch statement
switch (expression) {
Case takes value 1:
Execute the statement;
Break
.......
Case Value N:
Execute the statement;
Break
Default
Execute the statement;
}
An expression accepts only 4 types of values: byte, short, ING, char
The case is the matching value, if the matching walk, the corresponding execution statement; If all do not match, go to default.
Break indicates that the selection is out of bounds, and if it does not break, it will continue to execute down without judging the case after it has been matched.
The location of all case and default can be arbitrary.
3.1.3 Cycle structure
For, while, do and
1. For
for (initialization expression; loop condition; post-loop operation) {
Loop body (execution statement);
}
2. While
while (conditional expression) {
Loop body (execution statement);
}
3. Do While
do{
Loop body (execution statement);
}while (conditional expression);
Features: The loop body executes at least once, regardless of whether the condition is satisfied.
3.1.4 The simplest form of the infinite loop
for (;;) {}
while (true) {}
This article is from the "Java Basics" blog, so be sure to keep this source http://8163413.blog.51cto.com/8153413/1689727
Chapter III Program Flow control