1.
True or False: A loop is a control-structure used for repetition of certain statements.
Correct Answer
A. True
Explanation
A loop is a control structure that allows for the repetition of certain statements. It allows a set of instructions to be executed repeatedly until a certain condition is met. This is useful when there is a need to perform a task multiple times without writing the same code over and over again. Therefore, the statement that a loop is a control structure used for repetition of certain statements is true.
2.
True or False: The statements found within a while loop always execute.
Correct Answer
B. False
Explanation
The statements found within a while loop do not always execute. The while loop will only execute the statements if the condition specified in the while loop is true. If the condition is false from the beginning, the statements within the while loop will not be executed at all.
3.
True or False: A flag-controlled while loop uses a Boolean variable to control the loop.
Correct Answer
A. True
Explanation
A flag-controlled while loop uses a Boolean variable to control the loop. This means that the loop will continue to execute as long as the Boolean variable is true. Once the variable becomes false, the loop will exit. This type of loop is commonly used when there is a specific condition that needs to be met in order for the loop to continue executing.
4.
A loop that continues to execute endlessly is called a(n) ____ loop
Correct Answer
infinite
Explanation
An infinite loop is a loop that continues to execute endlessly without any condition or statement to break out of the loop. It can be caused by a programming error or intentionally used in certain situations where continuous execution is required. In an infinite loop, the program keeps repeating the same set of instructions indefinitely until it is manually interrupted or terminated. This can lead to the program becoming unresponsive or consuming excessive system resources.
5.
If the first two numbers of a Fibonacci sequence are 1 and 1 what is the seventh Fibonacci number?
Correct Answer
13
Explanation
The Fibonacci sequence starts with 1, 1, and each subsequent number is the sum of the two preceding numbers. So, the sequence goes 1, 1, 2, 3, 5, 8, 13. Therefore, the seventh Fibonacci number is 13.
6.
True or False: Any for loop can be written as a while loop.
Correct Answer
A. True
Explanation
Any for loop can be written as a while loop because both types of loops are used for repetitive execution of a block of code. The for loop provides a concise way to iterate over a range of values, while the while loop is more flexible and can be used for any condition-based repetition. By using appropriate initialization, condition, and update statements in a while loop, we can achieve the same functionality as a for loop. Therefore, it is true that any for loop can be written as a while loop.
7.
If the loop condition is initially ____, the loop body does not execute.
Correct Answer
B. False
Explanation
If the loop condition is initially False, the loop body does not execute because the loop condition is the condition that is checked before each iteration of the loop. If the condition is False from the beginning, it means that the loop condition is not met and therefore the loop body will not be executed.
8.
True or False: The statements in the body of a do…while loop execute at least once.
Correct Answer
A. True
Explanation
A do-while loop is a type of loop in programming where the statements in the body of the loop are executed first, and then the condition is checked. If the condition is true, the loop continues to execute. Since the statements in the body of the loop are executed before the condition is checked, it guarantees that the statements will be executed at least once, regardless of the condition. Therefore, the correct answer is True.
9.
do…while loops are called ____ loops because the condition is evaluated after the body of the loop is executed.
Correct Answer
post-test
post test
Explanation
The given statement describes the behavior of do...while loops, where the condition is evaluated after the body of the loop is executed. This means that the loop will always execute at least once before checking the condition. The terms "post-test" and "post test" both accurately describe this behavior, as they imply that the condition is evaluated after the loop body.