Chapter 6. Statements
CONTENTS Section 6.1 Simple Statements192Section 6.2 Declaration Statements193Section 6.3 Compound Statements (Blocks)193Section 6.4 Statement Scope194Section 6.5 The if Statement195Section 6.6 The switch Statement199Section 6.7 The while Statement204Section 6.8 The for Loop Statement207Section 6.9 The do while Statement210Section 6.10 The break Statement212Section 6.11 The continue Statement214Section 6.12 The goto Statement214Section 6.13 try Blocks and Exception Handling215Section 6.14 Using the Preprocessor for Debugging220Chapter Summary223Defined Terms223Statements 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++.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.