for Loops FRQ Practice

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

Question 1 of 5

A sign printer uses this loop:

for (int k = 4; k > 0; k--) {
    System.out.print(k);
}

(a) Identify the initialization, Boolean expression, and update. (b) How many times does the initialization run, and when is it compared with the first test? (c) State the displayed text and the number of body executions.

Question 2 of 5

Complete the missing trace cells. Then state the final value of p.

int p = 0;
for (int i = 1; i <= 3; i++) {
    p += i * 2;
}
Body i at body start p after body i after update i <= 3 for next test?
1 1
2
3

Question 3 of 5

Rewrite this for loop as an equivalent while loop. Keep the same loop control variable name and the same body.

for (int n = 1; n <= 5; n++) {
    System.out.print(n * n);
}

Then state the displayed text and explain where the update belongs relative to the body.

Question 4 of 5

A pile should receive 5, then 10, then 15, then 20.

(a) Write a for loop that adds those values into int pile, using a loop control variable in the header. (b) State the final pile. (c) State how many times the initialization runs and how many times the update runs.

Question 5 of 5

Compare these two fragments:

int a = 0;
for (int i = 0; i < 5; i++) {
    a += 3;
}

(a) Trace a after each body execution and state the final a. (b) Write an equivalent while loop, including the loop control variable. (c) If the for Boolean were changed to i <= 5, what would a become, and why is that an off-by-one versus i < 5?