Java self-study notes (6): Process Control

Theoretically, any complex program structure can have three basic structure of the program implemented by sequentially selecting, cycle.


Select structure

Selection control statement: if statement, if ··· else statement, if ··· else nested, switch statements, 

if (control condition) {statement 1; statement 2; ······}

 

 

if (control condition) {statement 1; statement 2; the else ??????} {statement 1; statement 2; ······}  

 

 

if (control condition) {statement 1; statement 2; ······} else if (control condition) {statement 1; statement 2; ······} else {statement 1; statement 2; ????? ???}  

 

Note: 1.else can not exist alone, you must have if, only else;

                     Pair 2.else statement and if that principle of proximity

                     3. rational use of braces achieve the corresponding functions, improve the readability of the program.

The switch statement also called multi-branch statement

format:

switch (Analyzing expression) {case: selecting values ​​1: statement block 1; BREAK;

                                    case: selecting values ​​2: 2 block of statements; BREAK;

                                   ·············································

                                    case: selecting values ​​n: statement block n; break;

                                    default: statement block n + 1;

                                    }


 

Cyclic structure of the main loop and the loop condition the two elements, the loop refers to the code executed repeatedly cycling conditions means conditions repeatedly performed.

While loop control statements

do while loop control statements

The for loop control statements

 

while format

[Condition] initialization

while (loop condition) {statement; cycle conditions change;}

 

 

do while format

 

[Condition] initialization

do {statement; cycling conditions change;}

while (loop condition) ;

This format will certainly execute the loop at least once

Note: The loop control variable must have an initial value before the loop

                  The body of the loop is only a logical statement, if it is more than, must be written in braces;

                  Finally, remember to modify the body of the loop the loop control variable

 

for loop format

for (initialization statement; cycling conditions; iteration statement) // initialization statement, loop condition, iterative statements can be null

{Statement;}

 

Each loop is composed of multiple nested within each cycle, i.e. the cycle into another inner loop


Jump control statements

Java language provides a break, continue, and return statements jump interrupt control, interrupt, respectively, and continue to return

 

break jump statements

1, with the switch statement indicates the end of a case, and exit the switch statement.

2, the loop control statements, indicate exits the loop.

continue jump statements

Only used in a loop statement. Its role is to terminate the current round of cycle, cycle skip the rest of the current round of statements, directly into the next round of the cycle

return statement

return statement is not to jump out of the loop, return more frequently used function is the end of a way to exit the current method, the method jumps to the top of the call

Guess you like

Origin www.cnblogs.com/tkj521Ya/p/11131101.html