Skip to main content

Imperative & Procedural Programming

Main Source:

Imperative Programming

Imperative Programming is a programming paradigm revolving around providing a sequence of statements or commands that change the program's state. It focuses on how a program should accomplish a task by specifying explicit instructions for the computer to follow.

Statements are executed in the order they appear, and each statement modifies the state of the program or performs an action. The program's execution follows a step-by-step approach, where each statement is executed sequentially.

Some characteristics of imperative programming:

Key characteristics of imperative programming include:

  • Assignment & Variables: Making variables by assigning data to it involve storing data in the memory. It acts as the state of the program, the variable can be modified during the program execution, which will change the program's behavior.

  • Control flow: Control flow such as loops and conditional statements which controls the flow of execution based on conditions. These structures determine which statements are executed and in what order.

  • Expressions and operators: Expressions perform computations or combine values, operators, such as arithmetic, logical, and comparison operators, are used to manipulate and evaluate expressions.

  • Modularity & Functions: Imperative programming breaks down its code into reusable functions that encapsulate specific tasks or computations. These functions can be called from various parts of the program.

Procedural Programming

Procedural Programming is a type of imperative programming, which emphasizes the use practice of organizing a program into procedures or functions, both share many similarities.

Procedural programming has more dedicated feature compared to imperative programming. In imperative programming which is used for lower-level language, some control flow are implemented using the goto statement, which transfers the program execution to a labeled statement elsewhere in the code. The use of goto statement may cause the program to become hard to maintain.

In contrast, procedural programming which is used in higher-level language, control flow has dedicated block scopes for control flow (e.g., while loop, if-else statement). A scope refers to the visibility and accessibility of variables within different parts of a program, it determines where a variable can be accessed and used within the program. Having dedicated scope allows the program to have more predictable and understandable control flow.