3.1.1 Procedural Programming
3.1.1 Procedural Programming
Imagine you have a recipe for baking cookies. It's a list of steps, one after another: "Mix flour and sugar," "Add eggs," "Stir well," "Bake for 10 minutes." You follow the instructions in order, and voilà, you get cookies!
Procedural Programming is a lot like that. It's one of the oldest and most straightforward ways to tell a computer what to do. In procedural programming, you write a series of steps (or procedures) that the computer follows in order.
Key Idea: The main idea is to break your program into smaller parts called procedures (also known as functions or subroutines). Each procedure does a specific job. For example, one procedure might calculate a number, another might print something on the screen, and another might save information.
How it Works:
- Instructions: You give the computer a list of commands.
- Order Matters: The computer runs these commands one by one, from top to bottom.
- Procedures/Functions: You can group related commands into a function and then "call" that function whenever you need that job done. This saves you from writing the same code over and over.
Example: Let's say you want to calculate the area of a rectangle. A procedural program might look like this (in plain English, not actual code):
- START
- Get the length of the rectangle.
- Get the width of the rectangle.
- Multiply the length by the width to find the area.
- Show the calculated area.
- END
This is a step-by-step procedure. Many older programming languages like Fortran and C are procedural, and even modern languages can be used in a procedural way.
Bibliography:
- GeeksforGeeks: https://www.geeksforgeeks.org/dbms/what-is-procedural-language/
- Wikipedia - Procedural Programming: https://en.wikipedia.org/wiki/Procedural_programming