Chapter 6. Statements


CONTENTS

Section 6.1 Simple Statements

192

Section 6.2 Declaration Statements

193

Section 6.3 Compound Statements (Blocks)

193

Section 6.4 Statement Scope

194

Section 6.5 The if Statement

195

Section 6.6 The switch Statement

199

Section 6.7 The while Statement

204

Section 6.8 The for Loop Statement

207

Section 6.9 The do while Statement

210

Section 6.10 The break Statement

212

Section 6.11 The continue Statement

214

Section 6.12 The goto Statement

214

Section 6.13 try Blocks and Exception Handling

215

Section 6.14 Using the Preprocessor for Debugging

220

Chapter Summary

223

Defined Terms

223


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++.

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++ Primer
C Primer Plus (5th Edition)
ISBN: 0672326965
EAN: 2147483647
Year: 2006
Pages: 223
Authors: Stephen Prata

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net