Reading and Tracing Code Under Time Pressure

tracing code

Part of: Exam Workshop: FRQ Strategies

Why Tracing Wins Points Many multiple choice questions and the early parts of FRQs ask you to predict what code outputs. The fastest, most reliable way is not to read the code and guess. It is to trace it by hand: keep a small table of every variable and update it line by line as the code runs. Under time pressure, a two-line table beats re-reading a loop five times. The Variable Table Write the variables across the top and add a row each time something changes. Here is a loop and its trace. Your table would track i and sum: after i = 1, sum = 1; after i = 2, sum = 3; after i = 3, sum = 6; after i = 4, sum = 10. The loop stops when i reaches 5, so the output is 10. Writing those four rows takes ten seconds and removes all doubt. Watch the Loop Boundaries The two spots that trip people are the loop start and the loop end. Check the initial value, then check the exact condition. i <= 4 runs for i equal to 1, 2, 3, 4. Change it to i < 4 and it stops at 3, giving sum = 6 instead. When a question offers answers that differ by one iteration, the trap is a boundary, so trace the first and last passes with care. Key points: - Trace with a small variable table, one row per change. - Verify

Challenge: Sum One to N