Deck 4: Performing Loops
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Match between columns
Question
Match between columns
Question
Match between columns
Question
Question
Question
Match between columns
Question
Match between columns
Question
Match between columns
Question
Match between columns
Question
Match between columns
Question
Match between columns
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/51
Play
Full screen (f)
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
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
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.
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
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
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
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
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
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
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
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.
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
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
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.
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
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
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
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
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
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
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
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
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
42
Match between columns
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
43
Match between columns
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
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
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
47
Match between columns
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
48
Match between columns
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
49
Match between columns
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
50
Match between columns
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
51
Match between columns
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck