switch(expression) { case Constant value 1: Statement body 1; break; case Constant value 2: Statement body 2; break; ... default: Statement body n+1; break; }

public static void main(String[] args) { //Define variables to determine the day of the week int weekday = 6; //switch Statement implementation selection switch(weekday) { case 1: System.out.println("Monday"); break; case 2: System.out.println("Tuesday"); break; case 3:
public static void main(String[] args) { int i = 5; switch (i){ case 0: System.out.println("implement case0"); break; case 5: System.out.println("implement case5"); case 10: System.out.println("implement case10"); default: System.out.println("implement default"); } }
Precautions for using switch statements:
1. the value after multiple case s cannot be repeated.
2. only the following data types can be found in the parentheses after the switch: basic data type: byte/short/char/int
Reference data type: String string, enum
3. the switch statement format can be flexible: the sequence can be reversed, and the break statement can be omitted. "The matching case will be executed downward from which position until a break or the overall end is encountered."
for(Initialization expression①; Boolean expression②; Step expression④){ Circulatory body③ }

public class demo02 { public static void main(String[] args) { //Console output 10 times HelloWorld,Do not use cycles System.out.println("HelloWorld"); System.out.println("HelloWorld"); System.out.println("HelloWorld"); System.out.println("HelloWorld"); System.out.println("HelloWorld"); System.out.println("HelloWorld"); System.out.println("HelloWorld"); System.out.println("HelloWorld"); System.out.println("HelloWorld"); System.out.println("HelloWorld"); System.out.println("‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐"); for(int x = 0; x < 10; x++) { System.out.println("HelloWorld"+x); } } }
The basic components of the circular structure can be generally divided into four parts: the basic components of the circular structure can be generally divided into four parts:
1. initialization statement: it is executed at the beginning of the loop and only once.
1. initialization statement: it is executed initially at the beginning of the loop and only once
2. condition judgment: If yes, the cycle continues; If not, the loop exits. 3. loop body: repeat the contents of things to be done and several lines of statements.
2. condition judgment: If yes, the cycle continues; If not, the loop exits. 3. loop body: repeat the contents of things to be done and several lines of statements.
4. step statement: the finishing work to be performed after each cycle. It must be executed once after the end of each cycle. Each step statement: the finishing work to be performed after each cycle. It must be executed once after the end of each cycle