Principles of Programming

Principles of Programming

Programming refers to the process of creating a set of instructions that tell a computer how to perform a task.

  • High-Level Languages: These languages are more user-friendly and closer to human language. Examples include Python and Java.
  • Low-Level Languages: These languages are closer to the machine language and are harder to understand. Examples include Assembly language and machine code.

Variables

Variables are used to store information that can be used in the program.

  • Declaration: This is where a variable is first introduced or named in the program.
  • Assignment: This is where a value is given to a variable.
  • Initialization: The process of declaring a variable and assigning it an initial value.

Data Structures

Data structures are specific ways to store and organize data in a computer’s memory.

  • Array: An array is a data structure that contains a collection of values which can be identified by an index.
  • Lists: Lists are similar to arrays, but they have dynamic sizes and can contain different types of data.

Control Structures

Control structures determine the flow of a program.

  • Sequence: This is the order in which instructions are executed, from top to bottom.
  • Selection: Involves making a decision, often using if, else or else if statements.
  • Iteration (loops): Involves repeating a section of code a number of times. Examples include for and while loops.

Subroutines

Subroutines are used to organise pieces of code which perform a specific task into separate, reusable units.

  • Functions: A type of subroutine that returns a value after execution.
  • Procedures: A type of subroutine that performs a specific task but does not return a value.

Error Handling

Error handling refers to the process of responding to and recovering from error conditions in a program.

  • Syntax errors: These occur when the rules of the programming language are not followed.
  • Runtime errors: These errors occur during the execution of a program.
  • Logical errors: These errors occur when the program runs without crashing, but gives incorrect output. This can happen because the logic of the program is wrong.