Java selection structure and branch structure (Ziph)

@Java

Selection structure and a branched structure summary module

Hello everyone, I'm Ziph!

Today, knowledge sharing content under the selected structure and branch structure, not more than that look directly down on the OK!
Mind mapping study in conjunction with better results! Click on the link below to enter the
Java selection structure and branch structure of the Mind Map (Ziph)

First, the basic structure selected if

grammar:

if(布尔表达式) {
	代码块//结果为true执行代码块
}
后续代码...

Implementation process:

  • Boolean expressions to judge
  • The result is true, the code block is executed first, and then perform subsequent code
  • The result is false, the code block is skipped, performed directly subsequent code

Two, if else selection structure

grammar:

if(布尔表达式) {
			//代码块1 
		} else {
			//代码块2
		}
		后续代码...

Implementation process:

  • Boolean expressions to judge
  • The result is true, the first block of code 1, then choose to abandon the entire structure, execute subsequent code
  • The result is false, the first block of code 2, and then choose to abandon the entire structure, execute subsequent code

Third, if multiple selection structure

grammar:

if(布尔表达式) {
			代码块1
		} else if (布尔表达式) {
			代码块2
		} else if (布尔表达式) {
			代码块3
		} else {
			代码块4
		}
		后续代码...

Note: mutually exclusive, when a condition is true, others are no longer performed, using the interval to determine (range conditions, followed in descending or ascending).

Fourth, if multiple selection structure

grammar:

if(外层布尔表达式){
		if(内层布尔表达式){
				内层代码块1
				}else{
				内层代码块2
				}
		}else{
			代码块2
		}
		后续代码...

Note: Select structure, alternative structures can be nested, can be any combination (if, if else, multiple IF), the nested serial structures may exist due to the writing of the result is not indented, and further performs a problem.

Five, switch branch structure

grammar:

switch(变量|表达式){ //可操作变量类型byte short int char String
		case 1:
			逻辑代码1;
			break;

		case 2:
			逻辑代码2;
			break;

		default:
			逻辑代码3;
			break;
		}
		后续代码...

Note: The case switch statement is selected, will not take the initiative to withdraw from this structure, the need to manually switch an additional break ;, out of the entire branch structure

Sixth, local variables

  • Concept: variable declared inside a function, you must first assign, re-use
  • Range: starting from the definition of the line, where the code block to the end, that is limited locally within the {}
  • Note: multiple variables within the scope overlap, do not allow the same name, otherwise it will compile error, not the normal program run

For questions, please leave a message reply, thank you!

Bye

Released six original articles · won praise 11 · views 826

Guess you like

Origin blog.csdn.net/weixin_44170221/article/details/104221628