The Java Tutorials have been written for JDK 8.Java教程是为JDK 8编写的。Examples and practices described in this page don't take advantage of improvements introduced in later releases and might use technology no longer available.本页中描述的示例和实践没有利用后续版本中引入的改进,并且可能使用不再可用的技术。See Java Language Changes for a summary of updated language features in Java SE 9 and subsequent releases.有关Java SE 9及其后续版本中更新的语言特性的摘要,请参阅Java语言更改。
See JDK Release Notes for information about new features, enhancements, and removed or deprecated options for all JDK releases.有关所有JDK版本的新功能、增强功能以及已删除或不推荐的选项的信息,请参阅JDK发行说明。
The if-then
statement is the most basic of all the control flow statements.if-then
语句是所有控制流语句中最基本的。It tells your program to execute a certain section of code only if a particular test evaluates to 它告诉您的程序只有在特定测试的计算结果为true
.true
时才执行特定的代码段。The 当“if”子句的计算结果为if-then-else
statement provides a secondary path of execution when an "if" clause evaluates to false
.false
时,if-then-else
语句提供了执行的辅助路径。Unlike 与if-then
and if-then-else
, the switch
statement allows for any number of possible execution paths.if-then
和if-then-else
不同,switch
语句允许任意数量的可能执行路径。The 当特定条件为真时,while
and do-while
statements continually execute a block of statements while a particular condition is true
.while
和do-while
语句持续执行语句块。The difference between do-while
and while
is that do-while
evaluates its expression at the bottom of the loop instead of the top.do-while
和while
之间的区别在于do-while
在循环的底部而不是顶部计算其表达式。Therefore, the statements within the 因此,do
block are always executed at least once.do
块中的语句始终至少执行一次。The for
statement provides a compact way to iterate over a range of values.for
语句提供了一种对一系列值进行迭代的紧凑方法。It has two forms, one of which was designed for looping through collections and arrays.它有两种形式,其中一种是为在集合和数组中循环而设计的。