92.4k views
2 votes
1. You need to write a loop that will repeat exactly 125 times. Which is the preferred loop construct to use? a. while loop b. do while loop c. for loop 2. You need to write a loop that will keep reading and adding integers to a sum, until the sum reaches or exceeds 21. The numbers are all less than 20 and the sum is initially 0. Which is the preferred loop construct to use? a. while loop b. do while loop c. for loop

1 Answer

2 votes

Answer:

1c

2b

Step-by-step explanation:

a) A for loop is suitable to create counters.

b) You know you can read an integer at least once, so it's OK to evaluate your continuation expression at the end of the loop.

However, while(...) { } and do {} while(...) constructs are very similar.

User Jan Czarny
by
5.3k points