Imperative programming
Imperative programming is a programming paradigm around executing statements that change the program's state.
What this means in human language:
- Programming paradigm: This is a set of concepts defining a style of building and structuring programs. Most programming languages, such as PHP, support multiple paradigms. We can also think of it as a mindset and a way we approach problems when using such paradigms.
- Statements: Units of action with side effects in imperative programming evaluated in sequences usually containing expressions. Statements are executed for their side effects and expressions for their return value. Consider this example:
$a = 2 + 5
This line of code is a statement where
2 + 5
is an expression. The expected side effect is assigning the valueÂ7
to theÂ$a
variable. This leads to changing the program's current state. Another statement could be, for instance:if ($a > 5) { }
This statement has one expression and no return value.
- State: Values of program variables in memory at any given time. In imperative programming, we define a series of statements that control the program's flow and, therefore, change its state.