Boxes for Values
Programs store numbers and words in named boxes called variables. Picture the box, read the label, watch the value change.
- 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
Finish first
Topic contents
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.
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?
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.
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 attemptedAssessment
Check your understanding
Answer each question, then read the explanation. That is where the learning is.
Finished this topic?
0 of 3 lessons marked done. Marking the topic complete ticks the rest.
