M3 CH5 Flashcards

1
Q

A ____________________________ - controlled loop uses a true/false condition to control the number of times that it repeats.
Boolean
condition
decision
count

A

condition

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

A __________________________- controlled loop repeats a specific number of times.
Boolean
condition
decision
count

A

count

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Each repetition of a loop is known as a(n) ______________________________.
cycle
revolution
orbit
iteration

A

iteration

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

The While loop is a _______________________ type of loop.
pretest
postest
prequalified
post iterative

A

pretest

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

The Do-While loop is a ______________________type of loop.
pretest
posttest
prequalified
post iterative

A

posttest

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

The For loop is a ______________________________________ type of loop.
pretest
posttest
prequalified
post iterative

A

pretest

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

A(n) _______________________________ loop has no way of ending and repeats until the program is interrupted.
indeterminate
interminable
infinite
timeless

A

infinite

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

A __________________________ loop always executes at least once.
pretest
postest
condition-controlled
count-controlled

A

postest

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

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.
sentinel
flag
signal
accumulator

A

sentinel

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

A condition-controlled loop always repeats a specific number of times.
True or False

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

The While loop is a pretest loop
True or False

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

The Do-While loop is a pretest loop.
True or False

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

You should not write code that modifies the contents of the counter variable in the body of a For loop.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

You cannot display the contents of the counter variable in the body of a loop.
True or False

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

It is not possible to increment a counter variable by any value other than 1.
True or False

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

The following statement decrements the variable x: Set x = x - 1.
True or False

17
Q

It is not necessary to initialize accumulator variables.
True or False.

18
Q

In a nested loop, the inner loop goes through all of its iterations for every single iteration of the outer loops.
True or False

19
Q

To calculate the total number of iterations of a nested loop, add the number of iterations of all the loops.
True or False

20
Q

Why should you indent the statements in the body of a loop?

A

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.

21
Q

Describe the difference between pretest loops and posttest loops.

A

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.

22
Q

What is a condition-controlled loop?

A

A condition-contrlled loop uses a true/false condition to control the number of times that it repeats.

23
Q

What is a count-controlled loop?

A

A count-controlled loop iterates a specific number of times.

24
Q

What is an infinite loop? Write the code for an infinite loop.

A

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

25
A For loop looks like what other loop in a flowchart?
While loop
26
Why is it critical that accumulator variables are properly initialized?
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.
27
What is the advantage of using a sentinel?
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.
28
Why must the value chosen for use as a sentinel be carefully selected?
A sentinel value must be unique enough that it will not be mistaken as a regular value in the list.