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
switchstatement. Execution transfers to the first statement following the terminated loop orswitch.case label Constant expression (§ 2.4.4, p. 65) that follows the keyword
casein aswitchstatement. No twocaselabels in the sameswitchstatement may have the same value.catch clause The
catchkeyword, an exception declaration in parentheses, and a block of statements. The code inside acatchclause 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
whileordo, to the next iteration in a rangefor, or to the expression in the header of a traditionalforloop.dangling else Colloquial term used to refer to the problem of how to process nested
ifstatements in which there are moreifs thanelses. In C++, anelseis always paired with the closest preceding unmatchedif. Note that curly braces can be used to effectively hide an innerifso that the programmer can control whichifa givenelseshould match.default label
caselabel that matches any otherwise unmatched value computed in theswitchexpression.do while statement Like a
while, except that the condition is tested at the end of the loop, not the beginning. The statement inside thedois 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
catchclause. This declaration specifies the type of exceptions thecatchcan handle.exception handler Code that deals with an exception raised in another part of the program. Synonym for
catchclause.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.
gotos obfuscate the flow of control within a program and should be avoided.if else statement Conditional execution of code following the
ifor 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 theifbody 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
switchkeyword. Control passes to the labeled statement with acaselabel that matches the value of the expression. If there is no matching label, execution either continues at thedefaultlabel, if there is one, or falls out of theswitchif there is nodefaultlabel.terminate Library function that is called if an exception is not caught.
terminateaborts the program.throw expression Expression that interrupts the current execution path. Each
throwthrows an object and transfers control to the nearest enclosingcatchclause that can handle the type of exception that is thrown.try block Block enclosed by the keyword
tryand one or morecatchclauses. If the code inside atryblock raises an exception and one of thecatchclauses matches the type of the exception, then the exception is handled by thatcatch. Otherwise, the exception is handled by an enclosingtryblock 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.