Process Control statements are divided into conditional statements, loop statements, and interrupt statements.
The interrupt statement consists of break and continue, the difference being that it jumps out of the loop, while continue jumps out of the loop, and then continues the next loop.
There are two kinds of conditional statements, the most used is if...else, which is not difficult, literally walk, if the expression in parentheses is true then go after the statement, if False then go to the statement in else, where only if () {...} section is required, in the following format:
if (Boolean expression 1) { //-expression 1 is true when the Operation}else if (Boolean expression 2) { //Expression 2 is true when the operation}else{//The above expression is false when the action}
The second is the switch switching statement, which is a bit cumbersome to use if statements, and is mainly used to replace multiple if...else if ... Loops, it is important to note that each case expression except the last case needs to be followed by a break, otherwise the expression will be executed to the first break or end of the statement, and the other literal types include:
1.char, Byte, short, int numbers, and their wrapper classes
2. Enumeration constants
3. String (starting from Java7.0)
The format is as follows:
Switch (variable) {case literal 1: //Operation break ; Case literal 2: //Operation break ; Case literal 3: //Operation break ; Default: //actions that do not meet the above conditions}
The loop statement includes the For loop, while loop, Do...while loop, and foreach Loop.
- foreach is the Java5.0 join loop, mainly for the array collection class object, which is characterized by no subscript, the use of the process does not have to develop a small standard, the same because there is no subscript so it is not suitable for the need to operate according to the subscript. Its format is
For (object obj:list) { //Perform action on object}
for (initialize counter; loop condition; update counter) { //loop operation}//Common template for (int i = 0; i < x; i++) { //action}
Look Back, Java restudying (ix): Java Basic Flow control statement