Chapter 4: Problem 3
What is a count-controlled loop?
Short Answer
Expert verified
Answer: A count-controlled loop is a type of loop in programming that runs a specific number of times, based on a predetermined count. It uses a counter variable to keep track of how many times it has run and terminates the loop when the counter reaches a certain value. An example of a count-controlled loop is a "for" loop. Here's an example that prints numbers from 1 to 5:
```
for (int counter = 1; counter <= 5; counter++) {
print(counter);
}
```
In this example, the counter variable starts at 1, the loop control condition checks that the counter is less than or equal to 5, and the increment statement increases the counter by 1 in each iteration. When the counter becomes 6, the loop ends.