What is sum after the following loop terminates?
```
int sum = 0;
int item = 0;
do {
item++;
sum += item;
if (sum > 4)
break;
}
while (item < 5);
```
a. 5
V
c. 7
d. 8
e. 9
b. 6
sum and item are initialized to 0 before the loop. In the loop, item++ increments item by 1 and item is then added to sum. If sum > 4, the break statement exits the loop. item is initially 0, then 1, 2, 3 and sum is initially 0, and then 1, 3, and 6. When sum is 6, (sum > 4) is true, which causes the break statement to be executed. So, the correct answer is B.
You might also like to view...
Assume proper includes have been executed, but not using directive or declaration. Write a definition of an iterator for a vector named vec of int values. Write a for loop that will display the contents vec on the screen, separated by spaces. Use iterators for the loop control.
What will be an ideal response?
If a network printing problem is related to the server or workstation, what are four areas you should check?
What will be an ideal response?
The ____ Tool softens hard edges or reduces detail in an image when you drag in the selection or image, by decreasing the color contrast between consecutive pixels.
a. Relax b. Blur c. Sharpen d. Round
When using a Calendar object on a Web form, you can reference ____.
A. the current time B. the current date C. the date selected by the user D. the calendar extension