CSC 10 Chapter 5

25 July 2022
4.7 (114 reviews)
30 test answers

Unlock all answers in this set

Unlock answers (26)
question
A ______-controlled loop uses a true/false condition to control the number of times that it repeats. a. Boolean b. condition c. decision d. count
answer
b. condition
question
A ______-controlled loop repeats a specific number of times. a. Boolean b. condition c. decision d. count
answer
d. count
question
Each repetition of a loop is known as a(n) ______. a. cycle b. revolution c. orbit d. iteration
answer
d. iteration
question
The While loop is a ______ type of loop. a. pretest b. posttest c. prequalified d. post iterative
answer
a. pretest
question
The Do-While loop is a ______ type of loop. a. pretest b. posttest c. prequalified d. post iterative
answer
b. posttest
question
The For loop is a ______ type of loop. a. pretest b. posttest c. prequalified d. post iterative
answer
a. pretest
question
A(n) ______ loop has no way of ending and repeats until the program is interrupted. a. indeterminate b. interminable c. infinite d. timeless
answer
c. infinite
question
A ______ loop always executes at least once. a. pretest b. posttest c. condition-controlled d. count-controlled
answer
b. posttest
question
A(n) ______ variable keeps a running total. a. sentinel b. sum c. total d. accumulator
answer
d. accumulator
question
A(n) ______ is a special value that signals when there are no more items from a list of items to be processed. This value cannot be mistaken as an item from the list. a. sentinel b. flag c. signal d. accumulator
answer
a. sentinel
question
True or False. A condition-controlled loop always repeats a specific number of times.
answer
False
question
True or False. The While loop is a pretest loop
answer
True
question
True or False. The Do-While loop is a pretest loop.
answer
False
question
True or False. You should not write code that modifies the contents of the counter variable in the body of a For loop.
answer
True
question
True or False. You cannot display the contents of the counter variable in the body of a loop.
answer
False
question
True or False. It is not possible to increment a counter variable by any value other than 1.
answer
False
question
True or False. The following statement decrements the variable x: Set x = x - 1.
answer
True
question
True or False. It is not necessary to initialize accumulator variables.
answer
False
question
True or False. In a nested loop, the inner loop goes through all of its iterations for every single iteration of the outer loops.
answer
True
question
True or False. To calculate the total number of iterations of a nested loop, add the number of iterations of all the loops.
answer
False
question
Why should you indent the statements in the body of a loop?
answer
By indenting the that statements in the body of the loop you visually set them apart from the surrounding code. This makes your program easier to read and debug. Also, this is similar to the style that most programmers follow when writing loops in actual code.
question
Describe the difference between pretest loops and posttest loops.
answer
Pretest loops tests its condition before performing an iteration. Because the test is done at the beginning of the loop, you usually have to perform some steps prior to the loop to make sure that the loop executes at least once. Posttest loops performs an iteration before testing its condition. The posttest loop always perform at least once iteration even if its condition is false to begin with.
question
What is a condition-controlled loop?
answer
A condition-contrlled loop uses a true/false condition to control the number of times that it repeats.
question
What is a count-controlled loop?
answer
A count-controlled loop iterates a specific number of times.
question
What three actions do count-controlled loops typically perform using the counter variable?
answer
Initialization, Test, and Increment
question
What is an infinite loop? Write the code for an infinite loop.
answer
An infinite loop continues to repeat until the program is interrupted. Infinite loops usually occur when the programmer forgets to write code inside the loop that makes the test condition false. Declare Integer awesome = 5 While awesome > 0 set awesome = awesome + 1 display awesome End While
question
A For loop looks like what other loop in a flowchart?
answer
While loop
question
Why is it critical that accumulator variables are properly initialized?
answer
When the loop finishes, the accumulator will contain the total of the numbers that were read by the loop. This is a critical step. Each time the loop reads a number, it adds it to the accumulator. If the accumulator starts with any value other than 0, it will not contain the correct total when the loop finishes.
question
What is the advantage of using a sentinel?
answer
When processing a long list of values with a loop, perhaps a better technique is to use a sentinel. A sentinel is a special value that marks the end of a list of items. When a program reads the sentinel value it knows it has reached the end of the list, so the loop terminates.
question
Why must the value chosen for use as a sentinel be carefully selected?
answer
A sentinel value must be unique enough that it will not be mistaken as a regular value in the list.