Defined Terms
block Sequence of zero or more statements enclosed in curly braces. A block is a statement, so it can appear anywhere a statement is expected.
break statement Terminates the nearest enclosing loop or
switch
statement. Execution transfers to the first statement following the terminated loop orswitch
.case label Constant expression (§ 2.4.4, p. 65) that follows the keyword
case
in aswitch
statement. No twocase
labels in the sameswitch
statement may have the same value.catch clause The
catch
keyword, an exception declaration in parentheses, and a block of statements. The code inside acatch
clause does whatever is necessary to handle an exception of the type defined in its exception declaration.compound statement Synonym for block.
continue statement Terminates the current iteration of the nearest enclosing loop. Execution transfers to the loop condition in a
while
ordo
, to the next iteration in a rangefor
, or to the expression in the header of a traditionalfor
loop.dangling else Colloquial term used to refer to the problem of how to process nested
if
statements in which there are moreif
s thanelse
s. In C++, anelse
is always paired with the closest preceding unmatchedif
. Note that curly braces can be used to effectively hide an innerif
so that the programmer can control whichif
a givenelse
should match.default label
case
label that matches any otherwise unmatched value computed in theswitch
expression.do while statement Like a
while
, except that the condition is tested at the end of the loop, not the beginning. The statement inside thedo
is executed at least once.exception classes Set of classes defined by the standard library to be used to represent errors. Table 5.1 (p. 197) lists the general-purpose exception classes.
exception declaration The declaration in a
catch
clause. This declaration specifies the type of exceptions thecatch
can handle.exception handler Code that deals with an exception raised in another part of the program. Synonym for
catch
clause.exception safe Term used to describe programs that behave correctly when exceptions are thrown.
expression statement An expression followed by a semicolon. An expression statement causes the expression to be evaluated.
flow of control Execution path through a program.
for statement Iteration statement that provides iterative execution. Ordinarily used to step through a container or to repeat a calculation a given number of times.
goto statement Statement that causes an unconditional transfer of control to a specified labeled statement elsewhere in the same function.
goto
s obfuscate the flow of control within a program and should be avoided.if else statement Conditional execution of code following the
if
or theelse
, depending on the truth value of the condition.if statement Conditional execution based on the value of the specified condition. If the condition is
true
, then theif
body is executed. If not, control flows to the statement following theif
.labeled statement Statement preceded by a label. A label is an identifier followed by a colon. Label identifiers are independent of other uses of the same identifier.
null statement An empty statement. Indicated by a single semicolon.
raise Often used as a synonym for throw. C++ programmers speak of “throwing” or “raising” an exception interchangeably.
range for statement Statement that iterates through a sequence.
switch statement A conditional statement that starts by evaluating the expression that follows the
switch
keyword. Control passes to the labeled statement with acase
label that matches the value of the expression. If there is no matching label, execution either continues at thedefault
label, if there is one, or falls out of theswitch
if there is nodefault
label.terminate Library function that is called if an exception is not caught.
terminate
aborts the program.throw expression Expression that interrupts the current execution path. Each
throw
throws an object and transfers control to the nearest enclosingcatch
clause that can handle the type of exception that is thrown.try block Block enclosed by the keyword
try
and one or morecatch
clauses. If the code inside atry
block raises an exception and one of thecatch
clauses matches the type of the exception, then the exception is handled by thatcatch
. Otherwise, the exception is handled by an enclosingtry
block or the program terminates.while statement Iteration statement that executes its target statement as long as a specified condition is
true
. The statement is executed zero or more times, depending on the truth value of the condition.