Analyze the following statement:

double sum = 0;
for (double d = 0; d < 10;) {
d += 0.1;
sum += sum + d;
}
a. The program has a compile error because the adjustment is missing in the for loop.
b. The program has a compile error because the control variable in the for loop cannot be of the double type.
c. The program runs in an infinite loop because d < 10 would always be true.
d. The program compiles and runs fine.


d In this loop, the loop initial action is d = 0, the continuation condition is d < 10, and the action-after-each-iteration is blank. Note that any of these three parts in the loop can be omitted. So, the loop is correct. The correction answer is (D).

Computer Science & Information Technology

You might also like to view...

Microsoft Outlook uses a special file format called a ____ to save your email files, calendar entries, and contacts.

A. Sensitivity level B. mailbox C. data file D. personal storage table

Computer Science & Information Technology

To display the conditional formatting options, you click the Conditional Formatting button in the:

A) Format group on the View tab. B) Styles group on the View tab. C) Styles group on the Home tab. D) Format group on the Home tab.

Computer Science & Information Technology

____ provides a baseline index point for evaluating coverage of tools and services.

A. Common Vulnerabilities and Exposures Database B. CERT Coordination Center C. SecurityFocus D. The National Vulnerability Database

Computer Science & Information Technology

If an event that creates a problem happens frequently, it is best to write instructions to take care of the problem with ____.

A. try...catch clauses B. conditional expressions C. exceptions D. try...catch...finally blocks

Computer Science & Information Technology