Jump to content

3.1.1 Procedural Programming

From Computer Science Knowledge Base

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):

  1. START
  2. Get the length of the rectangle.
  3. Get the width of the rectangle.
  4. Multiply the length by the width to find the area.
  5. Show the calculated area.
  6. 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: