🧭Imperative Programming
Also known as Imperative Code, Procedural Programming
Writing code as a list of steps that change values one at a time.
Think of it like
Think of it like a recipe. Do this, then this, then this, and the cake is done.
Example
Jack adds up three prices with a loop. Each turn adds one price to a running total, and the total ends at 12.
Why it matters
It is the closest match to how the machine works. Most code you meet is at least partly written this way.
Definition
Example code
python
total = 0
for p in [3, 4, 5]:
total = total + p
print(total) # 12Common mistake
Key takeaways
- 1Step by step. You say how.
- 2Values change. Each step updates them.
- 3Loops and ifs. Its main tools.