1: The most common looping statement for the for loop, base syntax . Used in cases where the number of cycles is known. for (initialize an expression; loop condition; action expression) { EXECUTE statement; ..... }
/* for loop writing format: for (initialization expression; loop condition; action expression) { Execute the statement; ..... } Initialization expression: Defines the number of times the variable, function, control loop condition: When the condition is true, the loop body is executed, and when the condition is false, the loop increment is ended: The case of the variable increment */ public class fordemo{ public static void main (string[] args) { for (int i = 0;i < 11; ++i) {System.out.println (i); } }}
/* Take advantage of the for loop to calculate the result of 1+4 1 + 2 + 3 + 4 = 10 1+2 and +3 1+2+3 and +4 */ public class fordemo_2{ public< /span> static void main (string[] args) { // Define variables, record the result after summing int sum = 0; for (int i = 0; I <= 4; ++i) {sum = sum + I; } System.out.println (sum); }}
2: Basic syntax--looping statements do ... while Do the. While loop statement is similar to the while Loop statement, the syntax structure Do { EXECUTE statement; ... } while (cyclic conditions);
Big Data <javase + Linux Elite Training class >_day_04