while Loops FRQ Practice

Responses receive AI feedback against a rubric after submission. Scores are practice estimates.

Question 1 of 5

A greenhouse mister is written as follows:

int moisture = 12;
while (moisture < 10) {
    moisture++;
    System.out.print("mist");
}

(a) Why is the body skipped? (b) Change only the starting moisture so the body runs exactly twice. State the output. (c) If moisture started at 8 and the update moisture++; were removed, what kind of loop would result?

Question 2 of 5

A clerk wants to stamp IDs 1 through 8 inclusive.

int id = 1;
int stamps = 0;
while (id < 8) {
    stamps++;
    id++;
}

(a) How many times does the body run, and which ID is missed? (b) Write a corrected condition so stamps becomes 8. (c) Explain why changing < to <= fixes this off-by-one, given that id++ remains in the body.

Question 3 of 5

Ribbon is cut into 5-centimeter pieces. Complete the missing trace cells. Then state the leftover ribbon and the number of cuts.

int ribbon = 17;
int cuts = 0;
while (ribbon >= 5) {
    ribbon -= 5;
    cuts++;
}
Check ribbon before body ribbon >= 5? ribbon after body cuts after body
1 17
2
3
4 (no body)

Question 4 of 5

Start with leftover = 25 and chops = 0.

(a) Write a while loop that subtracts 3 from leftover only while leftover is still strictly greater than 3. (b) State the final leftover and chops. (c) State how many times the Boolean is evaluated, including the failing last check.

Question 5 of 5

A seed counter is updated until it is no longer at most 40.

int seed = 3;
int days = 0;
while (seed <= 40) {
    seed = seed * 2 - 1;
    days++;
}

(a) Trace seed and days after each body execution. (b) State the final seed, days, and the number of condition tests. (c) Explain why the loop stops even though seed is not equal to 40.