while Loops FRQ Practice

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

Question 1 of 5

A locker starts with no leftover passes:

int leftover = 0;
while (leftover > 0) {
    leftover--;
    System.out.print("used");
}

(a) Does the body run? Explain using the first condition check. (b) Change only the starting value so the body runs exactly once, and state the output. (c) If leftover starts positive, describe one change that would make the loop infinite.

Question 2 of 5

A coach wants one whistle blast for each of 6 remaining drills.

int drills = 6;
int blasts = 0;
while (drills > 0) {
    blasts++;
}

(a) Explain why this loop is infinite. (b) Add one statement inside the body so blasts becomes 6 and the loop stops. (c) If the condition were drills >= 0, the body included drills--; and drills still started at 6, how many blasts would occur? Explain the off-by-one.

Question 3 of 5

A token booth gives 4 tokens per visit. Complete the missing trace cells. Then state the final values of tokens and visits.

int tokens = 9;
int visits = 0;
while (tokens >= 4) {
    tokens -= 4;
    visits++;
}
Check tokens before body tokens >= 4? tokens after body visits after body
1 9
2
3 (no body)

Question 4 of 5

A workshop starts with n = 1 and product = 1.

(a) Write a while loop that multiplies product by n for n = 1, 2, 3, and 4, updating n in the body. (b) State the final values of product and n. (c) State how many times the Boolean expression is evaluated, including the failing last check.

Question 5 of 5

A shuttle doubles remaining fuel units until the stored value is no longer less than 20.

int fuel = 3;
int burns = 0;
while (fuel < 20) {
    fuel *= 2;
    burns++;
}

(a) Trace fuel and burns after each body execution. (b) State the final fuel, burns, and the number of condition tests. (c) Rewrite the loop so it doubles only while the next doubling would still be at most 20, and state the new final fuel and burns.