switch selection structure

Chapter 4
Words:
switch switch
case case
default default
exit exit
consume consume
exception exception
syntax:
switch(expression){
case constant 1:
//code block 1;
break;
case constant 2:
//code block 2;
break;
default :
//code block
break;
}
*Note: here switch case break default is a keyword of java.
*switch structure is an equivalence judgment structure

1. Data types supported by expressions (*JDK1.7 and later):
①int (integer)
②String (string)
③short (short type)
④byte (byte type)
⑤char (character type )
⑥enumeration

2. Rules of
switch statement: ① The receiving type of the case statement must be consistent with the expression

The switch selection structure uses 4 keywords, introduction:
*switch: means "switch", this switch is the value in the parentheses after the switch keyword, and an integer variable (expression) or character variable ( expression).

*case: Indicates "situation, circumstance". The case must be followed by an integer or character constant, usually a fixed character or number. There can be multiple case blocks and the order can be changed, but the value of the constant after each case must be different.

*default: Indicates "default", that is, other conditions are not satisfied. default followed by a colon. The order of default blocks and case blocks can be changed without affecting the result of program execution. Usually, the dufault block is placed at the end, but can also be omitted.

*break: means "stop", that is, to jump out of the current loop.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325276870&siteId=291194637