Loop statements require the program to perform certain operations repeatedly based on conditions until the program is "satisfied".
The syntax format of the for loop statement is as follows:
for(expression1;expression2;expression3){//statement}
Notice:
1) Expression 2 must be an expression that evaluates to boolean data.
2) The compound statement is called the loop body. If the loop body has only one statement, the curly brackets {} can be omitted.
Execution rules for for loop statements:
(1) Calculate expression 1 and complete the necessary initialization work.
(2) Determine the value of expression 2. If the value of expression 2 is true, proceed to (3), otherwise proceed to (4).
(3) Execute the loop body, and then calculate expression 3 in order to change the loop condition and proceed to (2).
(4) End the execution of the for statement.
Example:
publicclassMain{publicstaticvoidmain(String[]args){for(inta=1;a<10;a=a+1){System.out.print(a);System.out.print(n);}}}
The running results are as follows:
123456789