229k views
2 votes
A counter-controlled loop may execute a constant number of iterations.
a) True
b) False

1 Answer

6 votes

Final answer:

A counter-controlled loop definitely executes a constant number of iterations when it is defined with a fixed limit for the counter. An example is a for loop with a set start, end condition, and increment value.

Step-by-step explanation:

Counter-controlled loops execute a constant number of iterations if they are set up with a fixed number as the counter limit. This is because the loop will continue to run until the counter reaches the predetermined limit. An example of a counter-controlled loop is a for loop in most programming languages. The number of iterations in such a loop is determined by the initial value, the limiting condition, and the increment/decrement steps specified by the programmer.

For example, the following is a for loop in Java that runs exactly 5 times:

for(int i = 0; i < 5; i++) {
// Body of the loop
}

In this case, because the initial value i starts at 0 and increments with each iteration until it reaches 4 (total of 5 iterations), the loop is guaranteed to run a constant number of times.

User Cybujan
by
7.4k points