Imperative Programming
Table of Contents
What’s Imperative Programming
Imperative programming focuses on explicitly specifying a sequence of statements that modify program state. It emphasizes how to achieve a result through step-by-step instructions and control flow structures like loops and conditionals.
Procedural programming and structured programming are subsets of imperative programming.
Languages
Procedural and object-oriented programming (OOP) languages fall under imperative programming, such as C, C++, C#, and Java.
Examples
The example calculates the sum of numbers from 1 to 10 using a for loop in Java.
int sum = 0;
for (int i = 1; i <= 10; i++) {
sum += i;
}
System.out.println("Sum: " + sum);
Declarative style is a contrast to the Imperative style
- See also: Declarative Programming
Ref.
- https://www.techtarget.com/whatis/definition/imperative-programming#:~:text=Imperative%20programming%20is%20a%20software,models%20are%20not%20called%20on.
- https://en.wikipedia.org/wiki/Imperative_programming