Java While Loop – Java While 循环

最后修改: 2020年 1月 2日

中文/混合/英文(键盘快捷键:t)

1. Overview

1.概述

In this article, we’ll look at a core aspect of the Java language – executing a statement or a group of statements repeatedly using a while loop.

在这篇文章中,我们将看看Java语言的一个核心方面–使用while循环重复执行一条或一组语句。

2. While Loop

2.While循环

The while loop is Java’s most fundamental loop statement. It repeats a statement or a block of statements while its controlling Boolean-expression is true.

while循环是Java最基本的循环语句。它重复一个语句或一个语句块,同时其控制布尔表达式为真。

The syntax of the while loop is:

while 循环的语法是。

while (Boolean-expression) 
    statement;

The loop’s Boolean-expression is evaluated before the first iteration of the loop – which means that if the condition is evaluated to false, the loop might not run even once.

循环的布尔表达式在循环的第一次迭代之前被评估–这意味着如果条件被评估为假,循环可能甚至一次都不会运行。

Let’s have a look at a simple example:

让我们看一下一个简单的例子。

int i = 0;
while (i < 5) {
    System.out.println("While loop: i = " + i++);
}

3. Conclusion

3.结论

In this quick tutorial, we explored Java’s while loop.

在这个快速教程中,我们探讨了Java的while循环。

As always, examples can be found over on GitHub.

一如既往,可以在GitHub上找到实例