Codele / Programming basics
Variables
A box can be filled from other boxes, and boxes never stay linked. Then comes the classic puzzle: swapping two cups of juice.
- A variable can be filled from other variables: total = price + fee.
- The computer stores the answer, not a link. Change price later and total stays as it was.
- = copies a value into a box. The box it came from keeps its value.
- Filling a box throws away what was in it, so two boxes cannot swap with just two lines.
- To swap, use a spare box: save one value, move the other, then use the saved one.
Loading the playable lesson…