Lesson 4 of 6 · 8 min · 2 hands-on steps
How Code Runs, Step by Step
Watch a program run in slow motion, one line at a time, and see memory change.
The computer reads like you do: top to bottom
A program runs one line at a time, from top to bottom. Each line can change what's stored in memory. A variable is a named box in memory that holds a value.
Use the buttons below to step through this tiny program. Watch the Variables box change after each line.
Two big ideas from that replay:
- Order matters. Line 3 can only use
coffeeandpricebecause they were created on lines 1 and 2. - Variables hold values, not formulas. When
coffeechanged on line 4,totalstayed 6.
Run it yourself
Every code example in this program has a Run button. Try this one, then change the numbers and run it again. Experimenting is how you learn.
The #1 habit of good programmers: before you run code, predict what it will do. Then run it. When you're wrong, you just learned something.
🧪 Practice: 2 steps
0 / 2 doneStep 1 of 2 · Predict, then run
Read this code before you run it. What will it print? Say it out loud, then press Run tests ▶.
Then change only the second line so the program prints 15.
Output appears here. Press Run or Ctrl/⌘ + Enter.
Step 2 of 2 · Order matters
These lines are in the wrong order, so the program prints the wrong thing.
Reorder them (cut and paste) so it prints Hello, Sam.
Output appears here. Press Run or Ctrl/⌘ + Enter.
✅ Check your understanding
In what order does a computer run your code?
After `let x = 2;` then `x = x * 3;`, what is x?
Create a free account to track your progress.