Explanation
1. The for keyword means when..., it is a commonly used loop sentence in actual development. Its grammatical form is slightly more complicated than the previous loop sentence, but After getting familiar with it, I found that its grammatical arrangement is relatively orderly, and loop control and loop body are clearly separated.
Execution process
2. Start the initial statement. Determine the loop condition. If the loop condition is false, end the loop, otherwise the next step will be executed. Execute the loop body. Execute the iteration statement. Skip to step 2 and repeat the execution. Note that each statement in the for statement can be empty, and the initial statement is only executed once when executing the for statement.
Example
int sum = 0; for (int i = 1; i <= 100; i++) { sum += i; } System.out.println("1累加到100的结果是:" + sum);
The above is the detailed content of What is the for statement in java. For more information, please follow other related articles on the PHP Chinese website!