Quiz4-RepetitionStructures Flashcards

1
Q

The following pseudocode is for a loop that will perform three iterations: (T/F)

For start = 6 To 2 step -3
Do something
End For

A

False. iterations is 2x
meaning 6-3=3
3-3= 0

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

The following pseudocode is for a loop that will perform three iterations: (T/F)
For start = 5 To 10 Step 2
Do something
End For

A

True:
start at 5 skip 2.
UNTIL value is 10.
5+2=7
7+2=9
9+2=11
STOP ITERATIONS BC 11>10

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

The Do-While loop is a posttest loop (T/F)

A

True

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

The while loop gets its name from the way it works: it does a task WHILE a condition is false (T/F)

A

False
while a condition is TRUE.

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

The test condition in a While loop must always be an integer value(T/F)

A

False

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

A while loop repeats infinitely when there is no statement inside the loop body that will make the test condition false(T/F)

A

True

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

For loops automatically increment or decrement a counter variable(T/F)

A

True

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

You can only use positive integers as step values in a For statement(T/F)

A

False

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

In a For loop the programmer must know the exact number of iterations the loop must perform before writing the code(T/F)

A

False

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

While and For loops are considered pretest loops because they test the condition before processing the statement or statements in the loop body(T/F)

A

True

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

A condition-controlled loop can be used to iterate the body of the loop a specific number of times(T/F)

A

True

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

In the following pseudocode counter is the accumulator(T/F):

For counter = 1 to 6
Set numberWidgets=numberwidgets+counter
End For

A

False:
The variable numberofwigdets is used as an accumulator to keep track of a running total as the loop iterates. The accumulator is incremented by the value of counter on each iteration of the loop.

After the loop has completed, the final value of the accumulator would be the sum of the numbers from 1 to 6

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

Which of the following is the structure that causes a statement or set of statements to execute repeatedly?

A

repetition structure

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

Which type of loop uses a Boolean expression to control the number of times a loop repeats?

A

Condition-Controlled loop

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

Which type of loop repeats a statement or set of statements as long as the Boolean expression IS FALSE?

A

Do-Until

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

Which type of loop is specifically designed to initialize, test, and increment or decrement a counter variable?

A

For loops

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

The amount by which the counter variable is incremented or decremented in a For loop is known as the:

A

Step amount

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

A loop that accumulates a total as it reads each number from a series is often said to keep a(n):

A

running total

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

Statements that appear between the While and the End While statements are known as the:

A

Loop Body

20
Q

A(n) ___________ represents a special value that marks the end of a list of values

A

Sentinel

21
Q

The following is an example of a ____________ loop:

While x < 10
Set sum = sum + x
Set x = x + 1
End While

A

Count-Controlled

22
Q

If an expression is False, the ________ operator will return True.

A

NOT

23
Q

How many times would the following loop iterate?

For j = 1 To 5 step 2
Display j
End For

A) 0

B) 5

C) 3

A

C) 3 iterations:
j=1
count up from 1 to including 5(limit) bc j is allowed to be any value 1 thru and including 5. count up and skip 2
1+2=3
3+2=5
5+2=7
7>5 so the loop ends

24
Q

How many times would the following loop iterate?

Set k = 1
While k <= 5
Display k
End While

A

infinite
bc k is not stepped it will always = 1
and 1 always <= 5

25
Q

How many times would the following loop iterate?
Set k = 1
While k > 5
Display k
End While

A

0 iterations
k=1 and will always be less than 5 NOT greater. therefore the loop will not execute bc the condition is not met

26
Q

How many times would the following loop iterate?

Set k = 1
Do
Display k
Set k = k +1
Until k > 2

A

2 iterations:
k=1
1+1=2
2+1=3
3>2 therefore loop ends

27
Q

How many times would the following loop iterate?

Set k = 1
While k < 5
Display k
Set k = k + 1
End While

A

4 iterations:
k=1 loop ends when k =5
1+1=2
2+1=3
3+1=4
4+1=5 this ends the loop bc 5 is not fed as a value bc it doesn’t match the given condition.

28
Q

How many times would the following loop iterate?

For m = 1 To 8 Step 3
Display m
End For

A

3 iterations:
m=1
sentinal = 8 step/skip 3
1+3=4
4+3=7
7+3=10
(loop ends bc 10 is not fed into the loop bc it does not meet the condition 8 limit)

29
Q

If the following pseudocode were coded and executed, assuming all variables have been declared as integer, what ould be the display?

Set x = 0
For m = 1 To 3
For p=1 to 3
Set x = x + p
End For
End for
Display x

A

18
x=18 bc of the nested loop structure
Since the inner loop iterates 3 times for each iteration of the outer loop, and the outer loop iterates 3 times, the inner loop will execute a total of 9 times.

Each time the inner loop executes, the value of p is added to x, so after all iterations have completed, the value of x will be (1 + 2 + 3) * 3 = 18.

30
Q

In the following pseudocode, which value is the accumulator?

Set x = 0
For m = 1 to 10
Set x = x + m
End For
Display x

A

x
accumulators are always initialized to 0 and added to the counter to keep a running total.

31
Q

Select all that apply
Which of the following cause(s) a statement or set of statements to repeat as long as a condition is True?

A) Do-While loops

B) For Loops

C) While Loops

D) Do-Until Loops

A

A, B, C)
Do While, While, and For Loops repeat as long as the condition is true

32
Q

Select all that apply.
Which of the following are posttest loops?

A) Do-Until

B) Do-While

C) For

A

A and B
Do until and Do While loops

33
Q

A(n) _____________ structure is commonly known as a loop.

A

repetition structure

34
Q

A(n) _______________ - controlled loop repeats a statement or set of statements a specific number of times.

A

count-controlled

35
Q

A(n) _________ loop continues to repeat until the program is interrupted.

A

infinite loop

36
Q

A count-controlled loop uses a variable known as a(n) ____________ to store the number of iterations that have been performed.

A

counter

37
Q

The variable that keeps a running total in a loop is known as a(n) _______________.

A

accumulator

38
Q

When processing a long list of values in a loop, the program knowns it has reached the end of the when the ____________ value is read.

A

sentinel

39
Q

In a For loop, a negative step value is used to _____________ the counter variable.

A

decrement

40
Q

In a count-controlled loop, the test action compares the counter variable to the _____________ value to determine if the loop iterates or terminates.

A

maximum

41
Q

A loop that iterates as long as a condition is false and then stops when the condition becomes true is known as a(n) _________ loop.

A

Do-Until loop

42
Q

*****When a(n) ___________ loop executes, the condition is tested at the beginning. If it is true, the loop body executes and the loop starts over. If it is false, the loop terminates.

A

**CHATGPT says While textbooks says While like wtf

43
Q

A structure that has a loop inside another loop is called a(n) ____________ loop.

A

Nested loop

44
Q

In a nested loop, the inner loop goes through all of its iterations for every iteration of the _____________ loop.

A

Outer loop

45
Q

The total number of ___________ of a nested loop is the product of the number of all the loops.

A

Iterations

46
Q

The ___________ statement is specifically designed to initialize, test, and increment or decrement a counter variable.

A

For