1. Select a statement

1.1 if statement

1. If (Boolean expression){Java statement; Java statements; 2. If (Boolean expression){Java statement; }else{Java statement; } 3. If (Boolean expression 1){}else if(Boolean expression 2){Java statement; }else if(Boolean expression 3){Java statement; }... 4. If (Boolean expression 1){}else if(Boolean expression 2){Java statement; }else if(Boolean expression 3){Java statement; }else{} If none of the above conditions are met, execute the elseCopy the code

1.2 Switch statement

Switch (value){case value 1: Java statement; Java statements; . break; Case value 2: Java statement; Java statements; . break; Case value 3: Java statement; Java statements; . break; Default: Java statement; } break; Statements are not required; The default branch is also not required. The value of the switch statement is int, and the value of the String statement is not supported in jdk8. Compare "value" with "value 1", execute the Java statement in that branch and then encounter a break statement, switch statement ends if not equal, then "value" and "value 2" do the same as above if the branch executes but the branch does not break at the end, Case penetration occurs (perform the preceding steps until break or default is encountered). If all cases are not matched successfully, execute default case penetration int num = 1. Switch (num){case 0: system.out.println (" Sunday "); break; Case 1: system.out.println (" Monday "); Case 2: system.out.println (" Tuesday "); Case 3: system.out.println (" Wednesday "); Case 4: system.out.println (" Thursday "); Case 5: system.out.println (" Friday "); break; Case 6: system.out.println (" Saturday "); // Monday Tuesday Wednesday Thursday Friday case merge int num = 2; Switch (num){case 1: case 2: case 3: system.out.println (" Monday "); break; Case 4: system.out.println (" Tuesday "); break; Case 5: system.out.println (" Wednesday "); break; Case 6: system.out.println (" Thursday "); break; Case 7: system.out.println (" Friday "); break; Case 8: system.out.println (" Saturday "); break; Default: system.out.println (" Sunday "); } // MondayCopy the code

2. Loop statements

2.1 For loop statements

For loop syntax format: for(initialization expression; Conditional expression; Update expression){loop body; // The body of the loop consists of Java statements; Java statements; Java statements; . } Note: The initial expression is executed first, and the conditional expression is executed only once throughout the loop. The result of the conditional expression must be a Boolean type. {system.out.println (" infinite loop "); }Copy the code

2.2 While loop statements

While loop syntax format: while(Boolean expression){loop body; While (true){system.out.println (" dead loop ");} {system.out.println (" dead loop ");} {system.out.println (" dead loop "); }Copy the code

2.3 the do… While loop statement

do... While loop syntax format: do{loop body; }while(); Execution principle: Execute the loop body first, and then judge the conditions. If the value is true, continue to execute. If the value is false, end the loop bodyCopy the code