Skip to content
BENIBIX Learn

Imperative Programming

Development🧭 Programming ParadigmsParadigm Basics

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

Imperative programming means writing code as a list of steps. Each step changes something. You tell the computer exactly how to reach the answer, one move at a time. Loops, if statements and variables that change are its main tools. Most beginners learn to code this way first.

Example code

python
total = 0
for p in [3, 4, 5]:
    total = total + p
print(total)  # 12
Each step changes total, one price at a time.

Common mistake

Writing a 50-step loop where one built-in call would do. Look for the tool that says what you want.

Key takeaways

  1. 1
    Step by step. You say how.
  2. 2
    Values change. Each step updates them.
  3. 3
    Loops and ifs. Its main tools.

Compare