ConceptsAll the ideas

Rule Machines

Idea 16of 23Builds onTrace code in a table

Predict before you run

Why read code before you run it?

Today you'll discover

  • how to predict an output
  • how to check it against the goal
  • when to change code first

Think firstThe goal: an input of 10 should give 30

Before running it, predict: what will this code output for 10?

Decide first, then press Next. Work out the output before you look at the table.

Three blocks of code: MULTIPLY BY 2, ADD 5, OUTPUT, with the input 10 in the box and the goal 30 written above. The trace shows 10 to 20, then 20 to 25, and OUTPUT 25 is ringed. Then the code with ADD 10 instead: 10 to 20, 20 to 30, OUTPUT 30. The last step asks whether ADD 1, MULTIPLY BY 4 turns 4 into its goal of 20.

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

The big idea

Predict the output by reading the code, then compare it with the goal before you run it.

Read, predict, compare

Read each line. Predict the output. Compare it with the goal. Change the code if it misses. Then run it.

  1. Predict25
  2. Goal30
  3. ChangeADD 10
  4. Run30

Easy to get wrongCode does what it says, not what you meant. ADD 5 adds 5 even when the goal needs 10.

Key word

predict
to work out what will happen before it happens, such as what code will output before it runs

Ready to use it?

  • Predict what code will output, and say whether it meets its goal.
Practise this idea