Home > Java > Java Tutorial > body text

What is the for statement in java

王林
Release: 2023-05-18 11:40:06
forward
1544 people have browsed it

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);
Copy after login

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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!