Resources | Subject Notes | Computer Science
Structured programming is a programming paradigm that emphasizes the use of control flow structures to create well-organized and readable code. It avoids the use of the GOTO statement, which can lead to spaghetti code that is difficult to understand and maintain. The core principles involve using sequences, selections (if-then-else), and iterations (loops) to control the flow of execution.
Procedures and functions are fundamental building blocks of structured programming. They allow you to break down a complex task into smaller, more manageable units of code. Both procedures and functions encapsulate a sequence of instructions, providing a reusable block of code that can be called from different parts of the program.
Feature | Procedure | Function |
---|---|---|
Return Value | No explicit return value. | May or may not return a value. |
Usage | Executed as a standalone block of code. | Called as part of an expression; its return value can be used. |
Purpose | Typically performs a series of actions. | Typically performs a calculation and returns a result. |
A procedure is defined using the Procedure keyword (or a similar keyword depending on the programming language). It typically takes input parameters and performs a series of actions. The procedure is then called to execute the defined sequence of instructions.
Example (Conceptual):
Procedure CalculateArea(width, height)
Area = width * height
Display "Area: " + Area
A function is defined using the Function keyword (or a similar keyword). Functions are designed to perform a specific calculation and return a value. They are used to modularize code and avoid repetition.
Example (Conceptual):
Function CalculateArea(width, height)
Area = width * height
Return Area
Understanding the following terminology is crucial for working with procedures and functions:
Using procedures and functions is a cornerstone of writing well-structured and maintainable code. They promote code reuse, improve readability, and make programs easier to debug.