Trace Tables Worksheet Generator

Short programs in TeachSpark pseudocode with a built-in interpreter. No AI, no credits.

Grades 6 – 12No account needed

Short programs in TeachSpark's own pseudocode (with a printed syntax key) using variables, loops and conditions. A small interpreter built into the tool runs each program to produce the exact trace table. Never uses AP or IB exam pseudocode names or text. No AI, so it never uses a generation credit.

What students practice

  • Computer Science
  • Trace tables
  • Pseudocode

Live sample sheet

No account needed to view and print.
Name: ____________________Date: ____________

Trace Tables

1. Complete the trace table for the following program:
SET x = 13
SET y = 9
SET z = x + y
OUTPUT z
StepxyzSET x = 13SET y = 9SET z = x + yOUTPUT z
2. Complete the trace table for the following program with a FOR loop:
SET sum = 0
FOR i = 3 TO 7
SET sum = sum + i
NEXT i
OUTPUT sum
StepisumSET sum = 0FOR i = 3 TO 7SET sum = sum + iNEXT i → i = 4SET sum = sum + iNEXT i → i = 5SET sum = sum + iNEXT i → i = 6SET sum = sum + iNEXT i → i = 7SET sum = sum + iNEXT i → loop endsOUTPUT sum
3. Complete the trace table for the following program with an IF condition:
SET x = 17
SET y = 31
IF x > y THEN
SET result = x - y
END IF
OUTPUT result
StepxyresultSET x = 17SET y = 31IF x > y → falseOUTPUT result
4. Complete the trace table for the following program:
SET x = 6
SET y = 13
SET z = x + y
OUTPUT z
StepxyzSET x = 6SET y = 13SET z = x + yOUTPUT z
5. Complete the trace table for the following program with a FOR loop:
SET sum = 0
FOR i = 3 TO 6
SET sum = sum + i
NEXT i
OUTPUT sum
StepisumSET sum = 0FOR i = 3 TO 6SET sum = sum + iNEXT i → i = 4SET sum = sum + iNEXT i → i = 5SET sum = sum + iNEXT i → i = 6SET sum = sum + iNEXT i → loop endsOUTPUT sum
6. Complete the trace table for the following program with an IF condition:
SET x = 20
SET y = 46
IF x > y THEN
SET result = x - y
END IF
OUTPUT result
StepxyresultSET x = 20SET y = 46IF x > y → falseOUTPUT result
7. Complete the trace table for the following program:
SET x = 15
SET y = 7
SET z = x + y
OUTPUT z
StepxyzSET x = 15SET y = 7SET z = x + yOUTPUT z
8. Complete the trace table for the following program with a FOR loop:
SET sum = 0
FOR i = 1 TO 6
SET sum = sum + i
NEXT i
OUTPUT sum
StepisumSET sum = 0FOR i = 1 TO 6SET sum = sum + iNEXT i → i = 2SET sum = sum + iNEXT i → i = 3SET sum = sum + iNEXT i → i = 4SET sum = sum + iNEXT i → i = 5SET sum = sum + iNEXT i → i = 6SET sum = sum + iNEXT i → loop endsOUTPUT sum
Made with TeachSpark

Answer Key — Trace Tables

1. Complete the trace table for the following program:
SET x = 13
SET y = 9
SET z = x + y
OUTPUT z
StepxyzSET x = 1313——SET y = 9139—SET z = x + y13922OUTPUT z13922
Solution:
SET x = 13 → x=13, y=—, z=—
SET y = 9 → x=13, y=9, z=—
SET z = x + y → x=13, y=9, z=22
OUTPUT z → x=13, y=9, z=22
Answer: z = 22
2. Complete the trace table for the following program with a FOR loop:
SET sum = 0
FOR i = 3 TO 7
SET sum = sum + i
NEXT i
OUTPUT sum
StepisumSET sum = 0—0FOR i = 3 TO 730SET sum = sum + i33NEXT i → i = 443SET sum = sum + i47NEXT i → i = 557SET sum = sum + i512NEXT i → i = 6612SET sum = sum + i618NEXT i → i = 7718SET sum = sum + i725NEXT i → loop ends825OUTPUT sum825
Solution:
SET sum = 0 → i=—, sum=0
FOR i = 3 TO 7 → i=3, sum=0
SET sum = sum + i → i=3, sum=3
NEXT i → i = 4 → i=4, sum=3
SET sum = sum + i → i=4, sum=7
NEXT i → i = 5 → i=5, sum=7
SET sum = sum + i → i=5, sum=12
NEXT i → i = 6 → i=6, sum=12
SET sum = sum + i → i=6, sum=18
NEXT i → i = 7 → i=7, sum=18
SET sum = sum + i → i=7, sum=25
NEXT i → loop ends → i=8, sum=25
OUTPUT sum → i=8, sum=25
Answer: sum = 25
3. Complete the trace table for the following program with an IF condition:
SET x = 17
SET y = 31
IF x > y THEN
SET result = x - y
END IF
OUTPUT result
StepxyresultSET x = 1717——SET y = 311731—IF x > y → false1731—OUTPUT result1731—
Solution:
SET x = 17 → x=17, y=—, result=—
SET y = 31 → x=17, y=31, result=—
IF x > y → false → x=17, y=31, result=—
OUTPUT result → x=17, y=31, result=—
Answer: result = —
4. Complete the trace table for the following program:
SET x = 6
SET y = 13
SET z = x + y
OUTPUT z
StepxyzSET x = 66——SET y = 13613—SET z = x + y61319OUTPUT z61319
Solution:
SET x = 6 → x=6, y=—, z=—
SET y = 13 → x=6, y=13, z=—
SET z = x + y → x=6, y=13, z=19
OUTPUT z → x=6, y=13, z=19
Answer: z = 19
5. Complete the trace table for the following program with a FOR loop:
SET sum = 0
FOR i = 3 TO 6
SET sum = sum + i
NEXT i
OUTPUT sum
StepisumSET sum = 0—0FOR i = 3 TO 630SET sum = sum + i33NEXT i → i = 443SET sum = sum + i47NEXT i → i = 557SET sum = sum + i512NEXT i → i = 6612SET sum = sum + i618NEXT i → loop ends718OUTPUT sum718
Solution:
SET sum = 0 → i=—, sum=0
FOR i = 3 TO 6 → i=3, sum=0
SET sum = sum + i → i=3, sum=3
NEXT i → i = 4 → i=4, sum=3
SET sum = sum + i → i=4, sum=7
NEXT i → i = 5 → i=5, sum=7
SET sum = sum + i → i=5, sum=12
NEXT i → i = 6 → i=6, sum=12
SET sum = sum + i → i=6, sum=18
NEXT i → loop ends → i=7, sum=18
OUTPUT sum → i=7, sum=18
Answer: sum = 18
6. Complete the trace table for the following program with an IF condition:
SET x = 20
SET y = 46
IF x > y THEN
SET result = x - y
END IF
OUTPUT result
StepxyresultSET x = 2020——SET y = 462046—IF x > y → false2046—OUTPUT result2046—
Solution:
SET x = 20 → x=20, y=—, result=—
SET y = 46 → x=20, y=46, result=—
IF x > y → false → x=20, y=46, result=—
OUTPUT result → x=20, y=46, result=—
Answer: result = —
7. Complete the trace table for the following program:
SET x = 15
SET y = 7
SET z = x + y
OUTPUT z
StepxyzSET x = 1515——SET y = 7157—SET z = x + y15722OUTPUT z15722
Solution:
SET x = 15 → x=15, y=—, z=—
SET y = 7 → x=15, y=7, z=—
SET z = x + y → x=15, y=7, z=22
OUTPUT z → x=15, y=7, z=22
Answer: z = 22
8. Complete the trace table for the following program with a FOR loop:
SET sum = 0
FOR i = 1 TO 6
SET sum = sum + i
NEXT i
OUTPUT sum
StepisumSET sum = 0—0FOR i = 1 TO 610SET sum = sum + i11NEXT i → i = 221SET sum = sum + i23NEXT i → i = 333SET sum = sum + i36NEXT i → i = 446SET sum = sum + i410NEXT i → i = 5510SET sum = sum + i515NEXT i → i = 6615SET sum = sum + i621NEXT i → loop ends721OUTPUT sum721
Solution:
SET sum = 0 → i=—, sum=0
FOR i = 1 TO 6 → i=1, sum=0
SET sum = sum + i → i=1, sum=1
NEXT i → i = 2 → i=2, sum=1
SET sum = sum + i → i=2, sum=3
NEXT i → i = 3 → i=3, sum=3
SET sum = sum + i → i=3, sum=6
NEXT i → i = 4 → i=4, sum=6
SET sum = sum + i → i=4, sum=10
NEXT i → i = 5 → i=5, sum=10
SET sum = sum + i → i=5, sum=15
NEXT i → i = 6 → i=6, sum=15
SET sum = sum + i → i=6, sum=21
NEXT i → loop ends → i=7, sum=21
OUTPUT sum → i=7, sum=21
Answer: sum = 21
Answers computed by code. No AI, no credits.

Assumptions and Conventions

Assumptions:
  • Programs use TeachSpark pseudocode, not AP or IB exam pseudocode.
  • The interpreter runs each program step by step to produce the trace.
  • Variables start as undefined (shown as —) until they are assigned a value.
Conventions:
  • SET var = value — assign a value to a variable.
  • IF condition THEN ... END IF — execute the block only if the condition is true.
  • FOR i = start TO end ... NEXT i — repeat with i from start to end inclusive.
  • OUTPUT value — print a value.
  • Operators: + - * / and MOD (modulo), > < = >= <= <>
Made with TeachSpark

No account needed.

Frequently asked questions

Do students need an account to use the Trace Tables?

No. Students never need an account. They open a shared link or join with a code.

Can I print the Trace Tables without signing up?

Yes. This tool computes answers by code, so you can generate, preview and print worksheet without an account. A free account adds saving and student links.

How are the answers computed?

Every answer is computed by code and verified by a second independent method. No AI is used.

What grades is the Trace Tables for?

This tool fits Grades 6 – 12.

✓ No account needed to generate, preview and print. A free account adds saving and student links.

Sign in

What can I do?

Without an account

  • Generate sheets
  • Preview pages
  • Print or save as PDF
  • Make versions A, B, C
  • Make differentiated levels
  • Print answer keys
  • See the trust panel and Show the calculation
  • Try the on-screen practice
  • Report a problem

With a free account

  • Save to My library
  • Browse My library
  • Share revocable student links
  • Make QR codes
  • Turn sharing on or off

Students never need an account — they open a shared link or join with a code.

Sample output, computed by code — change the options and Generate to make your own
Name: ____________________Date: ____________

Trace Tables

1. Complete the trace table for the following program:
SET x = 20
SET y = 7
SET z = x + y
OUTPUT z
StepxyzSET x = 20SET y = 7SET z = x + yOUTPUT z
2. Complete the trace table for the following program with a FOR loop:
SET sum = 0
FOR i = 2 TO 8
SET sum = sum + i
NEXT i
OUTPUT sum
StepisumSET sum = 0FOR i = 2 TO 8SET sum = sum + iNEXT i → i = 3SET sum = sum + iNEXT i → i = 4SET sum = sum + iNEXT i → i = 5SET sum = sum + iNEXT i → i = 6SET sum = sum + iNEXT i → i = 7SET sum = sum + iNEXT i → i = 8SET sum = sum + iNEXT i → loop endsOUTPUT sum
3. Complete the trace table for the following program with an IF condition:
SET x = 30
SET y = 24
IF x > y THEN
SET result = x - y
END IF
OUTPUT result
StepxyresultSET x = 30SET y = 24IF x > y → trueSET result = x - yOUTPUT result
4. Complete the trace table for the following program:
SET x = 2
SET y = 16
SET z = x + y
OUTPUT z
StepxyzSET x = 2SET y = 16SET z = x + yOUTPUT z
5. Complete the trace table for the following program with a FOR loop:
SET sum = 0
FOR i = 3 TO 8
SET sum = sum + i
NEXT i
OUTPUT sum
StepisumSET sum = 0FOR i = 3 TO 8SET sum = sum + iNEXT i → i = 4SET sum = sum + iNEXT i → i = 5SET sum = sum + iNEXT i → i = 6SET sum = sum + iNEXT i → i = 7SET sum = sum + iNEXT i → i = 8SET sum = sum + iNEXT i → loop endsOUTPUT sum
6. Complete the trace table for the following program with an IF condition:
SET x = 28
SET y = 48
IF x > y THEN
SET result = x - y
END IF
OUTPUT result
StepxyresultSET x = 28SET y = 48IF x > y → falseOUTPUT result
7. Complete the trace table for the following program:
SET x = 18
SET y = 20
SET z = x + y
OUTPUT z
StepxyzSET x = 18SET y = 20SET z = x + yOUTPUT z
8. Complete the trace table for the following program with a FOR loop:
SET sum = 0
FOR i = 2 TO 5
SET sum = sum + i
NEXT i
OUTPUT sum
StepisumSET sum = 0FOR i = 2 TO 5SET sum = sum + iNEXT i → i = 3SET sum = sum + iNEXT i → i = 4SET sum = sum + iNEXT i → i = 5SET sum = sum + iNEXT i → loop endsOUTPUT sum
Made with TeachSpark

Answer Key — Trace Tables

1. Complete the trace table for the following program:
SET x = 20
SET y = 7
SET z = x + y
OUTPUT z
StepxyzSET x = 2020——SET y = 7207—SET z = x + y20727OUTPUT z20727
Solution:
SET x = 20 → x=20, y=—, z=—
SET y = 7 → x=20, y=7, z=—
SET z = x + y → x=20, y=7, z=27
OUTPUT z → x=20, y=7, z=27
Answer: z = 27
2. Complete the trace table for the following program with a FOR loop:
SET sum = 0
FOR i = 2 TO 8
SET sum = sum + i
NEXT i
OUTPUT sum
StepisumSET sum = 0—0FOR i = 2 TO 820SET sum = sum + i22NEXT i → i = 332SET sum = sum + i35NEXT i → i = 445SET sum = sum + i49NEXT i → i = 559SET sum = sum + i514NEXT i → i = 6614SET sum = sum + i620NEXT i → i = 7720SET sum = sum + i727NEXT i → i = 8827SET sum = sum + i835NEXT i → loop ends935OUTPUT sum935
Solution:
SET sum = 0 → i=—, sum=0
FOR i = 2 TO 8 → i=2, sum=0
SET sum = sum + i → i=2, sum=2
NEXT i → i = 3 → i=3, sum=2
SET sum = sum + i → i=3, sum=5
NEXT i → i = 4 → i=4, sum=5
SET sum = sum + i → i=4, sum=9
NEXT i → i = 5 → i=5, sum=9
SET sum = sum + i → i=5, sum=14
NEXT i → i = 6 → i=6, sum=14
SET sum = sum + i → i=6, sum=20
NEXT i → i = 7 → i=7, sum=20
SET sum = sum + i → i=7, sum=27
NEXT i → i = 8 → i=8, sum=27
SET sum = sum + i → i=8, sum=35
NEXT i → loop ends → i=9, sum=35
OUTPUT sum → i=9, sum=35
Answer: sum = 35
3. Complete the trace table for the following program with an IF condition:
SET x = 30
SET y = 24
IF x > y THEN
SET result = x - y
END IF
OUTPUT result
StepxyresultSET x = 3030——SET y = 243024—IF x > y → true3024—SET result = x - y30246OUTPUT result30246
Solution:
SET x = 30 → x=30, y=—, result=—
SET y = 24 → x=30, y=24, result=—
IF x > y → true → x=30, y=24, result=—
SET result = x - y → x=30, y=24, result=6
OUTPUT result → x=30, y=24, result=6
Answer: result = 6
4. Complete the trace table for the following program:
SET x = 2
SET y = 16
SET z = x + y
OUTPUT z
StepxyzSET x = 22——SET y = 16216—SET z = x + y21618OUTPUT z21618
Solution:
SET x = 2 → x=2, y=—, z=—
SET y = 16 → x=2, y=16, z=—
SET z = x + y → x=2, y=16, z=18
OUTPUT z → x=2, y=16, z=18
Answer: z = 18
5. Complete the trace table for the following program with a FOR loop:
SET sum = 0
FOR i = 3 TO 8
SET sum = sum + i
NEXT i
OUTPUT sum
StepisumSET sum = 0—0FOR i = 3 TO 830SET sum = sum + i33NEXT i → i = 443SET sum = sum + i47NEXT i → i = 557SET sum = sum + i512NEXT i → i = 6612SET sum = sum + i618NEXT i → i = 7718SET sum = sum + i725NEXT i → i = 8825SET sum = sum + i833NEXT i → loop ends933OUTPUT sum933
Solution:
SET sum = 0 → i=—, sum=0
FOR i = 3 TO 8 → i=3, sum=0
SET sum = sum + i → i=3, sum=3
NEXT i → i = 4 → i=4, sum=3
SET sum = sum + i → i=4, sum=7
NEXT i → i = 5 → i=5, sum=7
SET sum = sum + i → i=5, sum=12
NEXT i → i = 6 → i=6, sum=12
SET sum = sum + i → i=6, sum=18
NEXT i → i = 7 → i=7, sum=18
SET sum = sum + i → i=7, sum=25
NEXT i → i = 8 → i=8, sum=25
SET sum = sum + i → i=8, sum=33
NEXT i → loop ends → i=9, sum=33
OUTPUT sum → i=9, sum=33
Answer: sum = 33
6. Complete the trace table for the following program with an IF condition:
SET x = 28
SET y = 48
IF x > y THEN
SET result = x - y
END IF
OUTPUT result
StepxyresultSET x = 2828——SET y = 482848—IF x > y → false2848—OUTPUT result2848—
Solution:
SET x = 28 → x=28, y=—, result=—
SET y = 48 → x=28, y=48, result=—
IF x > y → false → x=28, y=48, result=—
OUTPUT result → x=28, y=48, result=—
Answer: result = —
7. Complete the trace table for the following program:
SET x = 18
SET y = 20
SET z = x + y
OUTPUT z
StepxyzSET x = 1818——SET y = 201820—SET z = x + y182038OUTPUT z182038
Solution:
SET x = 18 → x=18, y=—, z=—
SET y = 20 → x=18, y=20, z=—
SET z = x + y → x=18, y=20, z=38
OUTPUT z → x=18, y=20, z=38
Answer: z = 38
8. Complete the trace table for the following program with a FOR loop:
SET sum = 0
FOR i = 2 TO 5
SET sum = sum + i
NEXT i
OUTPUT sum
StepisumSET sum = 0—0FOR i = 2 TO 520SET sum = sum + i22NEXT i → i = 332SET sum = sum + i35NEXT i → i = 445SET sum = sum + i49NEXT i → i = 559SET sum = sum + i514NEXT i → loop ends614OUTPUT sum614
Solution:
SET sum = 0 → i=—, sum=0
FOR i = 2 TO 5 → i=2, sum=0
SET sum = sum + i → i=2, sum=2
NEXT i → i = 3 → i=3, sum=2
SET sum = sum + i → i=3, sum=5
NEXT i → i = 4 → i=4, sum=5
SET sum = sum + i → i=4, sum=9
NEXT i → i = 5 → i=5, sum=9
SET sum = sum + i → i=5, sum=14
NEXT i → loop ends → i=6, sum=14
OUTPUT sum → i=6, sum=14
Answer: sum = 14
Answers computed by code. No AI, no credits.

Assumptions and Conventions

Assumptions:
  • Programs use TeachSpark pseudocode, not AP or IB exam pseudocode.
  • The interpreter runs each program step by step to produce the trace.
  • Variables start as undefined (shown as —) until they are assigned a value.
Conventions:
  • SET var = value — assign a value to a variable.
  • IF condition THEN ... END IF — execute the block only if the condition is true.
  • FOR i = start TO end ... NEXT i — repeat with i from start to end inclusive.
  • OUTPUT value — print a value.
  • Operators: + - * / and MOD (modulo), > < = >= <= <>
Made with TeachSpark

Trace Tables - High school CS - On-level scaffold

Short programs in TeachSpark pseudocode with trace tables computed by a built-in interpreter. No AI, no credits.

Options

TeachSpark uses cookies and local storage to improve your experience and process payments securely. Learn More