Control Statements of Java -from The Complete Reference Java

Java'a program control statements can be put into three categories:

1.selection statements : if and switch

    if(condition) statement1;
    else statement2;

IF:
    if-else
    nested ifs
    the if-else-if ladder

Switch
Nested switch statements               
    switch(expression){
         case value1:
             //statement sequence
             break;
         case value2:
              //statement sequence
              break;
         ....
         case valueN:
                  //statement sequence
          break;
        default:
              //default statement sequence
    }

The expression must be of type byte,short,int or char, each of the values specified in the case statements
 must be of a type compatible with the expression. Each case value must be a unique literal( that is, it must
be a constant, not a variable). Duplicate case values are not allowed.

    The switch statement works like this: the value of expression is compared with each of the literal values in the case statements. If a match is found, the code sequence following that case statement is executed. If 
none of the constants matches the value of the expression, then the default statement is executed. However, the default statement is optional. If no case matches and no default is present, then no further action is taken.

The break statement is used inside the switch to terminate a statement sequence. This has the effect of "junping out" of the switch.

Java complier works:
    When it complies a switch statement, the Java complier will inspect each of the case constants and create a
"jump table" that it will use for selecting the path of execution depending on the value of the expression. Therefore, if you need to select among a large group of values, a switch statement will run much faster than the equivalent logic coded using a sequence of if-elses. The complier can do this bacause it knows that the case constants are all the same type and simply must be compared for equality with switch expression. The complier has no such knowledge of a long list of if expression.
   

2.iteration statements

        2.1.while

        2.2.do while

        2.3.for

3.jump

        3.1break

        3.1continue

        3.1return

 

阅读更多
想对作者说点什么? 我来说一句

Java The Complete Reference 10th Edition

2017年11月06日 110.33MB 下载

Java The Complete Reference(10th) epub

2017年10月13日 111.27MB 下载

Java The Complete Reference(10th) azw3

2017年10月13日 132.38MB 下载

java完全手册第8版源代码

2011年09月15日 101KB 下载

Java The Complete Reference 8th Edition

2012年09月21日 40.93MB 下载

没有更多推荐了,返回首页

不良信息举报

Control Statements of Java -from The Complete Reference Java

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭