Team LiB
Previous Section Next Section

Chapter Summary


C++ provides a fairly limited number of statements. Most of these affect the flow of control within a program:

C++ 提供了种类相当有限的语句,其中大多数都会影响程序的控制流:

while, for, and do while statements, which implement iterative loops

whilefor 以及 do while 语句,实现反复循环;

if and switch, which provide conditional execution


continue, which stops the current iteration of a loop


break, which exits a loop or switch statement

break,退出一个循环或 switch 语句;

goto, which transfers control to a labeled statement


try, catch, which define a try block enclosing a sequence of statements that might throw an exception. The catch clause(s) are intended to handle the exception(s) that the enclosed code might throw.

trycatch 语句,实现 try 块的定义,该语句包含一个可能抛出异常的语句序列,catch 子句则用来处理在 try 块里抛出的异常;

throw expressions, which exit a block of code, transferring control to an associated catch clause

throw 表达式,用于退出代码块的执行,将控制转移给相关的 catch 子句。

There is also a return statement, which will be covered in Chapter 7.

当然还有将在第七章介绍的 return 语句。

In addition, there are expression statements and declaration statements. An expression statement causes the subject expression to be evaluated. Declarations and definitions of variables were described in Chapter 2.

此外,C++ 还提供表达式语句和声明语句。表达式语句用于求解表达式。变量的声明和定义则已在第二章讲述过了。

Team LiB
Previous Section Next Section