Home > Java > javaTutorial > How to use the while statement in java

How to use the while statement in java

PHPz
Release: 2023-04-19 09:28:04
forward
3822 people have browsed it

Explanation

1. The Chinese meaning of the while keyword is when..., that is, when the condition is established, the corresponding code is executed in a loop. The while statement is the basic structure in the loop statement, and the syntax format is relatively simple.

Execution process

2. When executing the while statement, first determine the loop condition. When the loop condition is false, directly execute the subsequent code of the while statement. If the loop condition is true, When, the loop body code is executed and the loop condition is judged until the loop condition is not established.

Examples

int i = 1;
int sum = 0;
while (i <= 100) {
    sum += i;
    i++;
}
System.out.println("1累加到100的结果是:" + sum);
Copy after login

What collection classes are there in Java

Collections in Java are mainly divided into four categories:

1, List List: ordered, repeatable;

2, Queue queue: ordered, repeatable;

3, Set collection: non-repeatable;

4, Map mapping: unordered, unique keys, non-unique values.

The above is the detailed content of How to use the while 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