?

AP® Computer Science A

Free Version

Upgrade subject to access all content

Difficult

Debugging Code: Infinite While Loop

APCSA-6ZVZ1W

Which of the following loops is an example of an infinite loop (one that does not stop looping)?

I.

    int total = 0, num = 0; 
    while  (num<100)
    {
        total+=num;
        if (num<50)   
            num+=10;
    }

II.

    int total = 0, num = 0;
    while(total >=0 && num<100)
    {
        total+=num;
        if(num<50)
            num+=10;
    }

III.

    int total = 0, num = 0;
    while (true)
    {
        total+=num;
        if(total>100000)
            break;
    }
A

I only.

B

I and II only.

C

II and III only.

D

I and III only.

E

I, II, and III.