java common flow control statements

java program flow control statements is the simplest most basic process control, no specific grammatical structure, in the order code, followed by the implementation of the program in most of the code is executed so.

Execution flow: from top to bottom, in sequence. There are three

if. the implementation of the principle of

Later if () is a filled condition, for example, a 1 <0; 1 == '1' Analyzing expression and the like, may be '1', so that a single digit 0 expression, which invokes the Boolean ( ) method converted to Boolean true or false, then the corresponding code for performing Boolean value, the following examples ... else statement

The if statement

f statement: if (conditional expression) statement is executed {
}

if ... else statement: if (conditional expression) {execute statement; the else {}} statement execution

if…else if…else语句
if (conditional expression) {execute statement;} the else if (conditional expression) {Select the first condition satisfies a branch statement branch inlet; execute statement;} {execute the else statement;}

switch ... case statement

switch statement break

In the switch statement, break by definition, if this condition is met, the direct implementation of the corresponding code, and then the end judgment BREAK if not, the determination will be reached after the execution conditions of the respective codes is determined to continue the subsequent condition determination:

Select statement:

switch statement

switch (expression) {

case values:

Execute the statement;

break; switch expression
can only be a byte, short, int, char;

case values: ase statement is disordered; while that of the case is loaded into memory;

Executing the statement; case corresponding to the value found as the program entry, as the end of the break statement;

break;

default:

Execute the statement;

BREAK; (may be omitted)}

if statements and switch statements similarities and differences:

if:

              1、对具体的值进行判断;

              2、对区间进行判断;

              3、对运算结果是boolean类型的表达式进行判断;

switch:

              1、对具体的值进行判断;

              2、值的个数必须是有限的;

When determining the value of typically several fixed option as recommended Switch;

However, due to the switch can determine the choice is relatively small, the code is more complex, we have developed the if statement is more common;

for statement

for statement

The for loop is similar to while loop, all loop, but the wording is different

           for(初始化表达式;条件表达式;循环后表达式){

                          循环语句;

           }

                          for循环的执行顺序:首先执行初始化表达式,判断循环条件,如果条件返回值为true,执行循环语句,

Then after the execution of an expression to determine the loop condition again ......

           for循环与while循环的关系:

           1、for与while可以互换;

2, the variables may be defined for the loop initialization expression, just as in the application of the variable loop, a for loop is recommended to be timely release of memory space;

Nested for loop: Mind trap small circle, for example: public switched earth turn, hour and minute hands of the clock;

Infinite loop:

           while(true){

                          循环语句;

           }

           for( ;;){

                          循环语句;

           }

Terminator Cycle:

           break;

           注意:1、break必须使用在switch或者循环语句中;

                 2、在switch或循环语句中,break单独使用时,下面不允许有代码语句;

                 3、默认情况下,break只能跳出语句所属的最近一层循环;

           continue;

           注意:1、continue是终止本次循环,继续下一次循环;

If you want to cycle out of the specified location, may be used to add tags loop manner, can be specified from bounce out of position;

           flag1:for(

;;){

                          循环语句;

                          break flag1;

           }

Guess you like

Origin blog.csdn.net/weixin_44589117/article/details/89601781