Y11 02 CT7 Slides
Y11 02 CT7 Slides
Y11 02 CT7 Slides
Learning objectives
© Pearson Education Ltd 2021. Copying permitted for purchasing institution only.
Y11-02-CT7: Trace tables
Identifying errors
Believe it or not, they even use techniques that only require paper and
pencil.
Today, you’re going to learn how to use one such technique, namely a
trace table.
© Pearson Education Ltd 2021. Copying permitted for purchasing institution only.
Y11-02-CT7: Trace tables
Worked example
• Draw a table with a column for each variable and one for the
output.
• Add blank rows. You can always add more, if required.
num1 num2 count output
© Pearson Education Ltd 2021. Copying permitted for purchasing institution only.
Y11-02-CT7: Trace tables
Worked example
• Start at line 1 and work your way down to line 4.
• Execute the line in your head and fill in the table.
• It is customary to put all initialisations on one line.
• Thereafter, each line of code becomes a line in the trace table.
• Blank lines mean no change. num1 num2 count output
0 0
5
© Pearson Education Ltd 2021. Copying permitted for purchasing institution only.
Y11-02-CT7: Trace tables
Worked example
• Line 5 is a for loop. The first value of count is 0.
• Line 6 does a calculation and changes the value of num2.
• Go back to line 5, to check if count is outside range 3. It is not, so
value of count goes up.
num1 num2 count output
• Line 6 calculates num2 again.
0 0
5 0
0
1
5
© Pearson Education Ltd 2021. Copying permitted for purchasing institution only.
Y11-02-CT7: Trace tables
Worked example
• Go back to line 5, to check if count is outside range 3. It is not, so
value of count goes up.
• Line 6 calculates num2 again.
num1 num2 count output
0 0
5
0
0
1
5
2
10
© Pearson Education Ltd 2021. Copying permitted for purchasing institution only.
Y11-02-CT7: Trace tables
Worked example
• Go back to line 5. The value of count would be 3, so is out of
range. Come out of loop and continue with line 8.
• Line 8 prints a value to the display, so fill in the output column.
• There are no more lines, so you are finished.
num1 num2 count output
0 0
5
0
0
1
5
2
10
10
© Pearson Education Ltd 2021. Copying permitted for purchasing institution only.
Y11-02-CT7: Trace tables
• The first step is to try to figure out what the code actually does.
© Pearson Education Ltd 2021. Copying permitted for purchasing institution only.
Y11-02-CT7: Trace tables
• For example, by using test data and a trace table you can show your algorithm
works, even before writing the code.
© Pearson Education Ltd 2021. Copying permitted for purchasing institution only.
Y11-02-CT7: Trace tables
• Remember, this can be done even before the algorithm is written in code on
a computer.
© Pearson Education Ltd 2021. Copying permitted for purchasing institution only.
Y11-02-CT7: Trace tables
© Pearson Education Ltd 2021. Copying permitted for purchasing institution only.
Y11-02-CT7: Trace tables
© Pearson Education Ltd 2021. Copying permitted for purchasing institution only.