Skip to content
BENIBIX Learn

Imperative vs Declarative Programming

Imperative code lists the steps to reach an answer, one change at a time. Declarative code says what answer you want and lets the tool pick the steps.

Development🧭 Programming Paradigms

Imperative Programming

Writing code as a list of steps that change values one at a time.

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
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.
Full entry
Development🧭 Programming Paradigms

Declarative Programming

Writing code that says what you want, and lets the tool work out how.

Declarative programming means writing code that says what result you want. It does not list the steps. The language or tool works out the steps for you. SQL is the best-known example: you ask for rows, and the database picks how to find them. HTML and CSS work this way too. It often makes code shorter and easier to read.

Example
Lucy asks the database for each order over 50 euros. She never says how to find them. The database picks the way.
Why it matters
Saying what you want leaves room for the tool to find a faster way than you would.
Full entry

In one line

Imperative Programming
Writing code as a list of steps that change values one at a time.
Declarative Programming
Writing code that says what you want, and lets the tool work out how.