ConceptsAll the ideas

Rule Machines

Idea 3of 23Builds onCode is exact steps in order

A variable holds one number

Where does code keep the number it is working on?

Today you'll discover

  • what a variable is
  • how ADD and SUBTRACT change it
  • what SET does to it

Think firstYour game piece moves by code

The variable square starts empty. What does square hold right after the line ADD 4?

Decide first, then press Next. Watch the number in the box after each line.

Five blocks of code: SET 0, ADD 6, ADD 4, SUBTRACT 3, OUTPUT, beside a box named square. As an arrow moves down the code, the box holds 0, then 6, then 10, then 7, and a table records each line and the number after it. OUTPUT shows 7. The last step asks about SET 20, ADD 5, SET 3, ADD 1.

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

The big idea

A variable is a named box that holds one value; each line can change it.

The box, line by line

square holds 0, then 6, then 10, then 7. Only the newest number is kept.

  1. SET 00
  2. ADD 66
  3. ADD 410
  4. SUBTRACT 37

Easy to get wrongSET and ADD are different. ADD 3 makes the number 3 bigger; SET 3 makes the number exactly 3, whatever it was.

Key words

variable
a named box in code that holds one number, which the code can change
value
the number a variable holds right now

Ready to use it?

  • Track a variable's value through each line of code.
Practise this idea