← Home
Python For Loop Tracing Practice
For loops are the backbone of AP Computer Science and phone-screen warm-ups. Interviewers test whether you track the loop variable, off-by-one bounds, and side effects inside the body. Work through the static examples below, then generate unlimited AI problems.
Example problems
Range step
s = 0
for i in range(2, 8, 2):
s += i
print(s)Output: 12
Nested loop
for i in range(2):
for j in range(3):
print(i, j, end=' ')Output: 0 0 0 1 0 1 2
Modify while iterating
a = [1, 2, 3]
for x in a:
a.append(x * 2)
print(len(a))Output: 6