Chapter 6. Statements第六章 语句CONTENTS
Statements are analogous to sentences in a natural language. In C++ there are simple statements that execute a single task and compound statements that consist of a block of statements that execute as a unit. Like most languages, C++ provides statements for conditional execution and loops that repeatedly execute the same body of code. This chapter looks in detail at the statements supported by C++. 语句类似于自然语言中的句子。C++ 语言既有只完成单一任务的简单语句,也有作为一个单元执行的由一组语句组成的复合语句。和大多数语言一样,C++ 也提供了实现条件分支结构的语句以及重复地执行同一段代码的循环结构。本章将详细讨论 C++ 所支持的语句。 By default, statements are executed sequentially. Except for the simplest programs, sequential execution is inadequate. Therefore, C++ also defines a set of flow-of-control statements that allow statements to be executed conditionally or repeatedly. The if and switch statements support conditional execution. The for, while, and do while statements support repetitive execution. These latter statements are often referred to as loops or iteration statements. 通常情况下,语句是顺序执行的。但是,除了最简单的程序外,只有顺序执行往往并不足够。为此,C++ 定义了一组控制流语句,允许有条件地执行或者重复地执行某部分功能。if 和 switch 语句提供了条件分支结构,而 for、while 和 do while 语句则支持重复执行的功能。后几种语句常称为循环或者迭代语句。 ![]() |