Essential Programming Principles and Structures
Fundamental Programming Concepts
Statements and Instructions
Each of the orders or commands within a program that include constants, variables, operators, and expressions are called statements or instructions.
Program Definition
A program is a set of commands that transform data into understandable output.
Programming Language
A programming language is a set of symbols and syntactic and semantic rules that define the structure and meaning of its elements and expressions.
Judgments (Conditional Statements)
These are program orders that involve constants, variables, operators, and expressions, specifically referring to conditional or decision-making constructs, such as ‘Case’ statements.
Types of Statements
Input/Output Statements
Enable communication between peripherals and main memory.
Assignment Statements
Allow assigning values to variables.
Control Statements
Allow altering the execution flow of a program. They use conditional branching based on questions that support two types of responses (e.g., true/false).
Variable Declaration Statements
Allow reserving memory areas to hold data.
Procedures
A procedure is a set of statements grouped into a single unit, defined by the programmer.
Types of Control Structures
Sequential Control
Involves executing two or more statements one after the other.
Selection or Choice
Allows executing one set of statements or another, based on a condition’s value.
Iteration
Involves the repetition of one or more statements a specified number of times.
Counter
A counter is a variable whose value is increased or decremented by a constant amount each time a specific event or action occurs. It is used to track internal events, often within a loop.
Accumulator
An accumulator is a variable that collects a set of values, typically to obtain their sum in a single variable.
Cycle or Loop
A cycle or loop is a set of instructions that is repeated a finite number of times, and includes a condition that determines when the repetition ends. Loops can be nested inside each other, and several loops can exist at the same level, but they must not intertwine.
Structured Programming
Structured programming is a method of writing computer programs in a clear and organized manner. It primarily uses three structures: sequential, selective (selection), and iterative (repetition), thereby making the use of unconditional transfer instructions (like goto
) unnecessary and generally discouraged.
Advantages of Structured Programming
Easier to Understand: Programs can be read sequentially, eliminating the need to track unconditional jumps (
goto
) within code blocks, making the program’s logic clear.Clear Logic: Instructions are more connected and related, leading to more coherent program flow.
Reduced Testing Effort: Program structure is more visible, making error detection and correction significantly easier.
Reduced Maintenance Costs: Programs are simpler and easier to maintain.
Faster Programs: Optimization is often easier to achieve due to clearer structure.
Self-Explanatory Code Blocks: Enhances internal documentation and readability.
Avoidance of
goto
Statements: While the underlying concept of unconditional transfer is present in selection and iteration statements, direct use ofgoto
is discouraged, leading to cleaner and more predictable code.
Modular Programming
Modular programming is a programming paradigm that involves dividing a program into independent modules or subprograms to enhance readability and manageability.
Module Definition
A module is a distinct, self-contained part of a computer program.
Characteristics of Modules
Manageable Size: Modules are typically small, making them easier to understand, develop, and test.
Change Isolation: It is easier to isolate the potential impact of changes within a modular program, simplifying maintenance.
Independence: The more independent modules are from each other, the easier they are to work with, promoting reusability and parallel development.