What is sum after the following loop terminates?
```
int sum = 0;
int item = 0;
do {
item++;
if (sum >= 4)
continue;
sum += item;
}
while (item < 5);
```
a. 6
b. 7
c. 8
d. 9
e. 10
a. 6
In this loop, when sum >= 4, the continue statement is executed to exit the current iteration so the next statement sum += item after the if statement will not be executed. The loop keeps adding item to sum for item 1, 2, 3, and so on. So sum is 1, 2, and 6. When sum is 6, sum >=4 is true, the continue statement is executed to skip the rest of the iteration. When the loop ends, sum is still 6. So, the correct answer is A.
You might also like to view...
The command that reduces the file size of a video is:
A. Edit B. Trim C. Compress
The foot tap method associated with the Frog class is what type of method?
a. Primitive method b. Custom method c. Unique method d. World-level method e. None of these