Intro to computers and programming

Receive aemail containing the next unit.

Introduction to Programming

Basics of a Program

classification of data in computer science

Classification of data in computer science.

Programming is a powerful tool that allows us to give instructions to a computer. But before we can start writing code, it's important to understand the basic structure of a program. In this article, we will cover the fundamental components of a program: variables, data types, operators, expressions, and control structures.

Variables and Data Types

In programming, a variable is a named space in the computer's memory where a programmer can store data. This data can be of different types, such as:

  • Integer: Whole numbers, like 7 or 42.
  • Float: Decimal numbers, like 3.14 or 0.99.
  • String: Text, like "Hello, world!".
  • Boolean: True or false values.

The type of data that a variable holds is called its data type. Different programming languages have different data types, but the ones listed above are common to most languages.

Operators and Expressions

Operators are symbols that tell the computer to perform specific mathematical or logical manipulations. There are several types of operators, including:

  • Arithmetic operators: Perform mathematical operations like addition (+), subtraction (-), multiplication (*), and division (/).
  • Comparison operators: Compare two values and determine the relation between them. These include equals (==), not equals (!=), less than (<), and greater than (>).
  • Logical operators: Used to combine conditional statements. These include AND (&&), OR (||), and NOT (!).

An expression is a combination of one or more values, variables, and operators that the programming language interprets and computes to produce another value.

Control Structures

Control structures determine the flow of a program's execution. There are three basic types of control structures: sequence, selection, and loop.

  • Sequence: This is the default control structure. Instructions are executed one after another in the order in which they appear.
  • Selection: Used for decisions, branching — choosing between 2 or more alternative paths. if is a common selection structure.
  • Loop: Used for looping, i.e., repeating a piece of code multiple times in a row. Common looping structures include for, while, and do while loops.

Understanding these basics is the first step towards writing a program. In the next unit, we will look at how a program runs on a computer, and how to identify and fix common errors.