Repetition structures Flashcards
What type of loop structure repeats the code based on the value of Boolean expression?
condition-controlled loop
number-controlled loop
list-controlled loop
count-controlled loop
condition-controlled loop
A better way to repeatedly perform an operation is to write the statements for the task once, and then place the statements in a loop that will repeat the statements as many times as necessary.
TRUE
FALSE
TRUE
To get the total number of iterations of a nested loop, sum the number of iterations of all the loops.
TRUE
FALSE
FALSE
It is not possible to do a post-test loop using while in Python.
TRUE
FALSE
FALSE
In a flowchart, both the decision structure and the repetition structure use the diamond symbol to represent the condition that is tested.
TRUE
FALSE
TRUE
In a for loop, the main purpose of a _____ variable is to reference each item in a sequence as the loop iterates.
target
reference
running
accumulator
target
The loop in the following code is called _____
while True:
print(‘Reading….’)
Finite loop
True loop
Infinite loop
Definite loop
Infinite loop
In input validation loops, the first input operation is called the _____, and its purpose is to get the first input value that will be tested.
loop validation
prompting read
loop jumpstart
priming read
priming read
A _____ is a special value that marks the end of a sequence of items.
sentinel
running total
break
target variable
sentinel
The while loop is known as a pretest loop, which means it tests its condition before performing an iteration.
TRUE
FALSE
TRUE
Reducing the duplication of code is one of the advantages of using a loop structure.
TRUE
FALSE
TRUE
Both of the following clauses would generate the same number of loop iterations.
for num in range(4):
for num in range(1,5):
TRUE
FALSE
TRUE
What are the values that the variable num contains through the iterations of the following for loop?
for num in range (2,9,2):
2 ,4, 6, 8
1, 3 ,5, 7, 9
2, 5, 8
2, 3, 4, 5, 6, 7, 8, 9
2, 4, 6, 8
_____ is the process of inspecting data that has been input into a program in order to ensure that the data is valid before it is used in computation.
Input validation
Correcting data
Correcting input
Data validation
Input validation
When will the following terminate?
while keep_on_going != 999:
when keep_on_going refers to a value less than 999
when keep_on_going refers to a value not equal to 999
when keep_on_going refers to a value equal to 999
when keep_on_going refers to a value greater than 999
when keep_on_going refers to a value equal to 999