ConceptsAll the ideas

Rule Machines

Idea 8of 23Builds onA loop can make a pattern

Trace code in a table

How do you keep track of a number that changes many times?

Today you'll discover

  • how to set up a trace table
  • how to fill one row per line
  • how to read the output from it

Think firstSET 10, then REPEAT 3 TIMES: MULTIPLY BY 2, SUBTRACT 3

What is the number after the first pass of the loop?

Decide first, then press Next. Fill one row for every line that runs, in order.

Code: SET 10, REPEAT 3 TIMES with MULTIPLY BY 2 and SUBTRACT 3 inside, END, OUTPUT. A trace table with columns for the pass, the line that runs and the number: 10; pass 1, 10 to 20, 20 to 17; pass 2, 17 to 34, 34 to 31; pass 3, 31 to 62, 62 to 59; OUTPUT 59. The last step asks for the number after pass 2 of SET 2 with ADD 4 and MULTIPLY BY 2 inside.

See the whole ideathe big idea and the key word, in one place

The big idea

A trace table writes down every line as it runs, with the number after it.

The first rowsSET 10 gives 10. Pass 1: MULTIPLY BY 2 gives 20, then SUBTRACT 3 gives 17. Pass 2 starts from 17.

Easy to get wrongFinish every line of the loop body before you start the next pass. Pass 1 ends after SUBTRACT 3, not after MULTIPLY BY 2.

Key word

trace table
a table with one row for each line of code as it runs, and the number after that line

Ready to use it?

  • Fill in a trace table for a loop.
  • Find the number after any pass.
Practise this idea