Control Statements of Java -from The Complete Reference Java

原创 2006年06月06日 11:43:00

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

1.selection statements : if and switch

    if(condition) statement1;
    else statement2;

    nested ifs
    the if-else-if ladder

Nested switch statements               
         case value1:
             //statement sequence
         case value2:
              //statement sequence
         case valueN:
                  //statement sequence
              //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 while








Java The Complete Reference 10th Edition

  • 2017年11月06日 20:57
  • 110.33MB
  • 下载

Java The Complete Reference(10th) azw3

  • 2017年10月13日 17:01
  • 132.38MB
  • 下载

Complete reference of all STSADM operations (with parameters) in MOSS 2007 SP1

This is an update to my complete reference of all STSADM operations in Microsoft Office SharePoint S...
  • Neccoo
  • Neccoo
  • 2011年12月22日 12:57
  • 507

Java:The Complete Reference,J2SE 5 Edition

  • 2007年09月03日 17:18
  • 1.17MB
  • 下载

Java2:The Complete Reference

  • 2008年02月07日 20:37
  • 3.42MB
  • 下载

NET:Error Creating Control -"Object Reference Not Set To An Instance Of Object"

这几天,竟遇见些奇葩问题,有的实在懒的写了,这个比较有意思,以前没见过,写个文章记录下: Error Creating Control -"Object Reference Not Set To...
  • istend
  • istend
  • 2014年07月24日 17:06
  • 1009

LeetCode 19 — Remove Nth Node From End of List(C++ Java Python)

题目: Given a linked list, remove t...
您举报文章:Control Statements of Java -from The Complete Reference Java