Skip to content

Boxes for Values

Programs store numbers and words in named boxes called variables. Picture the box, read the label, watch the value change.

Class 9 to 10beginner16 min3 lessons
By the end you will be able to
  • Describe a variable as a labelled box for one value
  • Predict how a box changes after an assignment step
  • Explain why names like score beat names like x for beginners

Lesson 1 of 3

Labels on boxes

Imagine a shelf of labelled boxes. Box score holds 0. Box lives holds 3. When the program says score becomes score plus 1, you open the score box, add one, put the new number back.

Each box holds one value at a time. Putting a new value in replaces the old one. The label stays the same.

Watch the compare animation. See clear names versus vague single letters.

Continue

Lesson 2 of 3

Reading assignments in order

total equals price times count uses whatever is inside price and count right now. If price changes later, old totals do not auto-update until you run the line again.

Tracing tables list box names across the top and show each line updating them. That is the next topic.

Try on paper: lives starts at 3, then lives becomes lives minus 1 twice. What is left?

Continue

Lesson 3 of 3

Ready to trace

Before syntax in a language, you need the picture: boxes, labels, replacement. Every language copies that idea.

Open the trace table lab soon and watch boxes change row by row.

Good names are a kindness to future you when homework is due next week.

Continue

Practice

Work these out yourself

No answer key here on purpose: these are the questions worth thinking through before you move on. Open one and work it out.

0/3 attempted

Assessment

Check your understanding

Answer each question, then read the explanation. That is where the learning is.

0/4
  1. Question 1: A variable is most like what?
    Question 1 / 4

    A variable is most like what?

    Select an option first
  2. Question 2: score becomes score plus 1 mainly does what?
    Question 2 / 4

    score becomes score plus 1 mainly does what?

    Select an option first
  3. Question 3: Clear variable names help because what?
    Question 3 / 4

    Clear variable names help because what?

    Select an option first
  4. Question 4: Assigning a new value to a box does what to the old one?
    Question 4 / 4

    Assigning a new value to a box does what to the old one?

    Select an option first
4 of 4 questions left.

Finished this topic?

0 of 3 lessons marked done. Marking the topic complete ticks the rest.