Documentation

The Java™ Tutorials
Hide TOC
Summary of Control Flow Statements控制流语句的小结
Trail: Learning the Java Language
Lesson: Language Basics
Section: Control Flow Statements

Summary of Control Flow Statements控制流语句的小结

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-then-else statement provides a secondary path of execution when an "if" clause evaluates to false.当“if”子句的计算结果为false时,if-then-else语句提供了执行的辅助路径。Unlike if-then and if-then-else, the switch statement allows for any number of possible execution paths.if-thenif-then-else不同,switch语句允许任意数量的可能执行路径。The while and do-while statements continually execute a block of statements while a particular condition is true.当特定条件为真时,whiledo-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-whilewhile之间的区别在于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.它有两种形式,其中一种是为在集合和数组中循环而设计的。


Previous page: Branching Statements
Next page: Questions and Exercises: Control Flow Statements