C++ provides a limited number of statements. Most of these affect the flow of control within a program:
•
while
,for
, anddo while
statements, which provide iterative execution.
•
if
andswitch
, which provide conditional execution.
•
continue
, which stops the current iteration of a loop.
•
break
, which exits a loop orswitch
statement.
•
goto
, which transfers control to a labeled statement.
•
try
andcatch
, which define atry
block enclosing a sequence of statements that might throw an exception. Thecatch
clause(s) are intended to handle the exception(s) that the enclosed code might throw.
•
throw
expression statements, which exit a block of code, transferring control to an associatedcatch
clause.
•
return
, which stops execution of a function. (We’ll coverreturn
statements in Chapter 6.)
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.