Deck 4: Performing Loops

Full screen (f)
exit full mode
Question
In the following segment of code,
Number = 1;
While(number
The body of the loop is ____.

A) empty
B) cout
C) cout
D) number
Use Space or
up arrow
down arrow
to flip the card.
Question
The following loop will execute ____ time(s).
Number = 1;
While(number

A) 1
B) 9
C) 10
D) an infinite number of
Question
What common pitfall can you identify in the following segment of code?
Number = 1;
While(number

A) The programmer failed to initialize the loop control variable.
B) An unwanted semicolon was added.
C) The programmer forgot the curly braces.
D) It assumes C++ is case sensitive.
Question
A ____ loop is one that must execute a specific number of times.

A) while
B) do-while
C) definite
D) count-controlled
Question
If the expression in the while statement is true, the ____ executes, and the Boolean expression is tested again.

A) conditional expression
B) iterator
C) loop body
D) inner loop
Question
Many programmers recommend that you initialize every variable in your programs.
Question
The initialize portion of a for loop ____.

A) is mandatory
B) can appear in any order in the for statement
C) is separated by a comma from the evaluate portion
D) can contain multiple statements
Question
The initialize portion of a for loop comes after the evaluate portion.
Question
The segment of code shown below displays "Hello!" ____ times:
Int count;
Const int NUM_LOOPS = 5;
Count = 0;
While( count

A) 0
B) 4
C) 5
D) 6
Question
If a program runs for several seconds and appears to be doing nothing or produces repeated output, you should suspect an infinite loop.
Question
A loop body can be a single statement or a block of statements.
Question
If you fail to initialize a loop control variable, C++ will automatically assign a value of 0 to the variable.
Question
The do-while loop is a(n) ____ loop.

A) pretest
B) posttest
C) nested
D) inner
Question
The following loop will execute ____ time(s).
Number = 1;
While(number

A) 1
B) 9
C) 10
D) an infinite number of
Question
In the following segment of code,
Number = 1;
While(number
The body of the loop is ____.

A) empty
B) everything in between the curly brackets
C) cout
D) number
Question
What common pitfall can you identify in the following segment of code?
Number = 1;
While(number

A) The programmer failed to initialize the loop control variable.
B) An unwanted semicolon was added.
C) The programmer forgot the curly braces.
D) The programmer failed to alter the loop control variable.
Question
As a custom, many programmers use the variable names i and ____ as iterators.

A) a
B) e
C) j
D) x
Question
It is preferable to initialize loop control variables at the beginning of a program.
Question
In C++, a(n) ____ has an unknown value and is of no practical use.

A) garbage value
B) iterator
C) sentinel value
D) loop control variable
Question
What common pitfall can you identify in the following segment of code?
Int number;
While(number

A) The programmer failed to initialize the loop control variable.
B) An unwanted semicolon was added.
C) The programmer forgot the curly braces.
D) It assumes C++ is case sensitive.
Question
Most often the evaluate part of the for statement compares the loop control variable with a ____________________ or limit.
Question
What happens if you fail to initialize a loop control variable?
Question
A priming _________________________ is an input statement that initializes a variable before a loop begins.
Question
The while loop and the for loop are ____ loops.

A) pretest
B) posttest
C) nested
D) inner
Question
To create a loop that executes at least one time, you should use a ____ loop.

A) for
B) while
C) do-while
D) pretest
Question
When you write a loop, what actions must be taken with the loop control variable?
Question
A loop that completely contains another is a(n) ____ loop.

A) protecting
B) parent
C) covering
D) outer
Question
The body of a do-while loop executes ____.

A) zero or more times
B) at least one time
C) at most one time
D) any number of times
Question
A(n) ____________________ loop is one in which the loop control variable is tested after the loop body executes.
Question
In what situations would you typically use a loop?
Question
What types of variables should be initialized?
Question
What kind of C++ expression can be placed inside the parentheses in the while statement?
Question
When you place another loop within a loop, the loops are ____ loops.

A) inner
B) nested
C) inside
D) outer
Question
A loop that falls entirely within the body of another is a(n) ____ loop.

A) inner
B) child
C) restricted
D) connected
Question
What is a priming input statement?
Question
Totals are ____________________ by processing individual records one at a time in a loop and adding numeric data to a total.
Question
What types of mistakes are easy to make when working with loops?
Question
When should the loop control variable be initialized?
Question
In most C++ compilers you can stop an infinite loop from executing by pressing the Ctrl + ____________________ or Ctrl + Break keys.
Question
The most difficult aspect of working with ____ loops is keeping track of the separate loop control variables that direct the program's execution.

A) nested
B) count-controlled
C) outer
D) definite
Question
Match between columns
tests the loop-continuing condition at the end, or bottom, of the loop
while loop
tests the loop-continuing condition at the end, or bottom, of the loop
sentinel value
tests the loop-continuing condition at the end, or bottom, of the loop
loop body
tests the loop-continuing condition at the end, or bottom, of the loop
do-while loop
tests the loop-continuing condition at the end, or bottom, of the loop
garbage value
tests the loop-continuing condition at the end, or bottom, of the loop
pretest loop
tests the loop-continuing condition at the end, or bottom, of the loop
loop control variable
tests the loop-continuing condition at the end, or bottom, of the loop
iterator
tests the loop-continuing condition at the end, or bottom, of the loop
for loop
Question
Match between columns
loop in which loop control variable is tested before the loop body is executed
while loop
loop in which loop control variable is tested before the loop body is executed
sentinel value
loop in which loop control variable is tested before the loop body is executed
loop body
loop in which loop control variable is tested before the loop body is executed
do-while loop
loop in which loop control variable is tested before the loop body is executed
garbage value
loop in which loop control variable is tested before the loop body is executed
pretest loop
loop in which loop control variable is tested before the loop body is executed
loop control variable
loop in which loop control variable is tested before the loop body is executed
iterator
loop in which loop control variable is tested before the loop body is executed
for loop
Question
Match between columns
used only to count the executions of a loop
while loop
used only to count the executions of a loop
sentinel value
used only to count the executions of a loop
loop body
used only to count the executions of a loop
do-while loop
used only to count the executions of a loop
garbage value
used only to count the executions of a loop
pretest loop
used only to count the executions of a loop
loop control variable
used only to count the executions of a loop
iterator
used only to count the executions of a loop
for loop
Question
Write a program that projects sales goals for a salesperson for the next several years.The user should be prompted for a first year's merchandise sales amount and a number of years to project the goals. For the first year, the salesperson's goal is the current sales amount. After that, sales are projected to grow at a rate of 8 percent per year. You should use a do-while loop.
Question
Write a while loop equivalent to the following for loop:
int count;
for(count = 1; count
Question
Match between columns
contains sections that initialize, evaluate, and alter a loop control variable
while loop
contains sections that initialize, evaluate, and alter a loop control variable
sentinel value
contains sections that initialize, evaluate, and alter a loop control variable
loop body
contains sections that initialize, evaluate, and alter a loop control variable
do-while loop
contains sections that initialize, evaluate, and alter a loop control variable
garbage value
contains sections that initialize, evaluate, and alter a loop control variable
pretest loop
contains sections that initialize, evaluate, and alter a loop control variable
loop control variable
contains sections that initialize, evaluate, and alter a loop control variable
iterator
contains sections that initialize, evaluate, and alter a loop control variable
for loop
Question
Match between columns
uninitialized variable
while loop
uninitialized variable
sentinel value
uninitialized variable
loop body
uninitialized variable
do-while loop
uninitialized variable
garbage value
uninitialized variable
pretest loop
uninitialized variable
loop control variable
uninitialized variable
iterator
uninitialized variable
for loop
Question
Match between columns
value that determines when a loop will end
while loop
value that determines when a loop will end
sentinel value
value that determines when a loop will end
loop body
value that determines when a loop will end
do-while loop
value that determines when a loop will end
garbage value
value that determines when a loop will end
pretest loop
value that determines when a loop will end
loop control variable
value that determines when a loop will end
iterator
value that determines when a loop will end
for loop
Question
Match between columns
controls the execution of a loop body
while loop
controls the execution of a loop body
sentinel value
controls the execution of a loop body
loop body
controls the execution of a loop body
do-while loop
controls the execution of a loop body
garbage value
controls the execution of a loop body
pretest loop
controls the execution of a loop body
loop control variable
controls the execution of a loop body
iterator
controls the execution of a loop body
for loop
Question
Match between columns
contains the statements that execute within a loop
while loop
contains the statements that execute within a loop
sentinel value
contains the statements that execute within a loop
loop body
contains the statements that execute within a loop
do-while loop
contains the statements that execute within a loop
garbage value
contains the statements that execute within a loop
pretest loop
contains the statements that execute within a loop
loop control variable
contains the statements that execute within a loop
iterator
contains the statements that execute within a loop
for loop
Question
Match between columns
repetition structure that executes as long as a tested expression is true
while loop
repetition structure that executes as long as a tested expression is true
sentinel value
repetition structure that executes as long as a tested expression is true
loop body
repetition structure that executes as long as a tested expression is true
do-while loop
repetition structure that executes as long as a tested expression is true
garbage value
repetition structure that executes as long as a tested expression is true
pretest loop
repetition structure that executes as long as a tested expression is true
loop control variable
repetition structure that executes as long as a tested expression is true
iterator
repetition structure that executes as long as a tested expression is true
for loop
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/51
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 4: Performing Loops
1
In the following segment of code,
Number = 1;
While(number
The body of the loop is ____.

A) empty
B) cout
C) cout
D) number
C
2
The following loop will execute ____ time(s).
Number = 1;
While(number

A) 1
B) 9
C) 10
D) an infinite number of
D
3
What common pitfall can you identify in the following segment of code?
Number = 1;
While(number

A) The programmer failed to initialize the loop control variable.
B) An unwanted semicolon was added.
C) The programmer forgot the curly braces.
D) It assumes C++ is case sensitive.
C
4
A ____ loop is one that must execute a specific number of times.

A) while
B) do-while
C) definite
D) count-controlled
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
5
If the expression in the while statement is true, the ____ executes, and the Boolean expression is tested again.

A) conditional expression
B) iterator
C) loop body
D) inner loop
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
6
Many programmers recommend that you initialize every variable in your programs.
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
7
The initialize portion of a for loop ____.

A) is mandatory
B) can appear in any order in the for statement
C) is separated by a comma from the evaluate portion
D) can contain multiple statements
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
8
The initialize portion of a for loop comes after the evaluate portion.
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
9
The segment of code shown below displays "Hello!" ____ times:
Int count;
Const int NUM_LOOPS = 5;
Count = 0;
While( count

A) 0
B) 4
C) 5
D) 6
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
10
If a program runs for several seconds and appears to be doing nothing or produces repeated output, you should suspect an infinite loop.
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
11
A loop body can be a single statement or a block of statements.
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
12
If you fail to initialize a loop control variable, C++ will automatically assign a value of 0 to the variable.
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
13
The do-while loop is a(n) ____ loop.

A) pretest
B) posttest
C) nested
D) inner
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
14
The following loop will execute ____ time(s).
Number = 1;
While(number

A) 1
B) 9
C) 10
D) an infinite number of
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
15
In the following segment of code,
Number = 1;
While(number
The body of the loop is ____.

A) empty
B) everything in between the curly brackets
C) cout
D) number
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
16
What common pitfall can you identify in the following segment of code?
Number = 1;
While(number

A) The programmer failed to initialize the loop control variable.
B) An unwanted semicolon was added.
C) The programmer forgot the curly braces.
D) The programmer failed to alter the loop control variable.
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
17
As a custom, many programmers use the variable names i and ____ as iterators.

A) a
B) e
C) j
D) x
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
18
It is preferable to initialize loop control variables at the beginning of a program.
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
19
In C++, a(n) ____ has an unknown value and is of no practical use.

A) garbage value
B) iterator
C) sentinel value
D) loop control variable
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
20
What common pitfall can you identify in the following segment of code?
Int number;
While(number

A) The programmer failed to initialize the loop control variable.
B) An unwanted semicolon was added.
C) The programmer forgot the curly braces.
D) It assumes C++ is case sensitive.
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
21
Most often the evaluate part of the for statement compares the loop control variable with a ____________________ or limit.
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
22
What happens if you fail to initialize a loop control variable?
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
23
A priming _________________________ is an input statement that initializes a variable before a loop begins.
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
24
The while loop and the for loop are ____ loops.

A) pretest
B) posttest
C) nested
D) inner
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
25
To create a loop that executes at least one time, you should use a ____ loop.

A) for
B) while
C) do-while
D) pretest
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
26
When you write a loop, what actions must be taken with the loop control variable?
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
27
A loop that completely contains another is a(n) ____ loop.

A) protecting
B) parent
C) covering
D) outer
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
28
The body of a do-while loop executes ____.

A) zero or more times
B) at least one time
C) at most one time
D) any number of times
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
29
A(n) ____________________ loop is one in which the loop control variable is tested after the loop body executes.
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
30
In what situations would you typically use a loop?
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
31
What types of variables should be initialized?
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
32
What kind of C++ expression can be placed inside the parentheses in the while statement?
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
33
When you place another loop within a loop, the loops are ____ loops.

A) inner
B) nested
C) inside
D) outer
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
34
A loop that falls entirely within the body of another is a(n) ____ loop.

A) inner
B) child
C) restricted
D) connected
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
35
What is a priming input statement?
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
36
Totals are ____________________ by processing individual records one at a time in a loop and adding numeric data to a total.
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
37
What types of mistakes are easy to make when working with loops?
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
38
When should the loop control variable be initialized?
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
39
In most C++ compilers you can stop an infinite loop from executing by pressing the Ctrl + ____________________ or Ctrl + Break keys.
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
40
The most difficult aspect of working with ____ loops is keeping track of the separate loop control variables that direct the program's execution.

A) nested
B) count-controlled
C) outer
D) definite
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
41
Match between columns
tests the loop-continuing condition at the end, or bottom, of the loop
while loop
tests the loop-continuing condition at the end, or bottom, of the loop
sentinel value
tests the loop-continuing condition at the end, or bottom, of the loop
loop body
tests the loop-continuing condition at the end, or bottom, of the loop
do-while loop
tests the loop-continuing condition at the end, or bottom, of the loop
garbage value
tests the loop-continuing condition at the end, or bottom, of the loop
pretest loop
tests the loop-continuing condition at the end, or bottom, of the loop
loop control variable
tests the loop-continuing condition at the end, or bottom, of the loop
iterator
tests the loop-continuing condition at the end, or bottom, of the loop
for loop
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
42
Match between columns
loop in which loop control variable is tested before the loop body is executed
while loop
loop in which loop control variable is tested before the loop body is executed
sentinel value
loop in which loop control variable is tested before the loop body is executed
loop body
loop in which loop control variable is tested before the loop body is executed
do-while loop
loop in which loop control variable is tested before the loop body is executed
garbage value
loop in which loop control variable is tested before the loop body is executed
pretest loop
loop in which loop control variable is tested before the loop body is executed
loop control variable
loop in which loop control variable is tested before the loop body is executed
iterator
loop in which loop control variable is tested before the loop body is executed
for loop
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
43
Match between columns
used only to count the executions of a loop
while loop
used only to count the executions of a loop
sentinel value
used only to count the executions of a loop
loop body
used only to count the executions of a loop
do-while loop
used only to count the executions of a loop
garbage value
used only to count the executions of a loop
pretest loop
used only to count the executions of a loop
loop control variable
used only to count the executions of a loop
iterator
used only to count the executions of a loop
for loop
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
44
Write a program that projects sales goals for a salesperson for the next several years.The user should be prompted for a first year's merchandise sales amount and a number of years to project the goals. For the first year, the salesperson's goal is the current sales amount. After that, sales are projected to grow at a rate of 8 percent per year. You should use a do-while loop.
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
45
Write a while loop equivalent to the following for loop:
int count;
for(count = 1; count
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
46
Match between columns
contains sections that initialize, evaluate, and alter a loop control variable
while loop
contains sections that initialize, evaluate, and alter a loop control variable
sentinel value
contains sections that initialize, evaluate, and alter a loop control variable
loop body
contains sections that initialize, evaluate, and alter a loop control variable
do-while loop
contains sections that initialize, evaluate, and alter a loop control variable
garbage value
contains sections that initialize, evaluate, and alter a loop control variable
pretest loop
contains sections that initialize, evaluate, and alter a loop control variable
loop control variable
contains sections that initialize, evaluate, and alter a loop control variable
iterator
contains sections that initialize, evaluate, and alter a loop control variable
for loop
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
47
Match between columns
uninitialized variable
while loop
uninitialized variable
sentinel value
uninitialized variable
loop body
uninitialized variable
do-while loop
uninitialized variable
garbage value
uninitialized variable
pretest loop
uninitialized variable
loop control variable
uninitialized variable
iterator
uninitialized variable
for loop
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
48
Match between columns
value that determines when a loop will end
while loop
value that determines when a loop will end
sentinel value
value that determines when a loop will end
loop body
value that determines when a loop will end
do-while loop
value that determines when a loop will end
garbage value
value that determines when a loop will end
pretest loop
value that determines when a loop will end
loop control variable
value that determines when a loop will end
iterator
value that determines when a loop will end
for loop
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
49
Match between columns
controls the execution of a loop body
while loop
controls the execution of a loop body
sentinel value
controls the execution of a loop body
loop body
controls the execution of a loop body
do-while loop
controls the execution of a loop body
garbage value
controls the execution of a loop body
pretest loop
controls the execution of a loop body
loop control variable
controls the execution of a loop body
iterator
controls the execution of a loop body
for loop
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
50
Match between columns
contains the statements that execute within a loop
while loop
contains the statements that execute within a loop
sentinel value
contains the statements that execute within a loop
loop body
contains the statements that execute within a loop
do-while loop
contains the statements that execute within a loop
garbage value
contains the statements that execute within a loop
pretest loop
contains the statements that execute within a loop
loop control variable
contains the statements that execute within a loop
iterator
contains the statements that execute within a loop
for loop
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
51
Match between columns
repetition structure that executes as long as a tested expression is true
while loop
repetition structure that executes as long as a tested expression is true
sentinel value
repetition structure that executes as long as a tested expression is true
loop body
repetition structure that executes as long as a tested expression is true
do-while loop
repetition structure that executes as long as a tested expression is true
garbage value
repetition structure that executes as long as a tested expression is true
pretest loop
repetition structure that executes as long as a tested expression is true
loop control variable
repetition structure that executes as long as a tested expression is true
iterator
repetition structure that executes as long as a tested expression is true
for loop
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 51 flashcards in this deck.