Logo of Computer Classes

Fundamentals and principles of basic programming

In many languages, if we want the variable to be used throughout the program we must name it as a global variable, otherwise, if we do not define it as global, by default the language will consider it a local variable.

A local variable when leaving the place where we have assigned a value, will lose that value and will no longer exist (when leaving an algorithm, a piece of program, the object, an IF structure, etc.).

In most languages the word global is put, a period and after the name of the variable, in this way, this variable can be used in all parts of the program.

Example global.pepe, which will be different from the variable pepe.

We will use them as local in all the examples, so you will never see the word global.

Control structures

The control structures have a fairly defined purpose: their objective is to indicate the order in which the steps of an algorithm or a program have to follow one another.

The control structures are of three types:




Let's start with the first ones.

Sequential structures

A sequential control structure, in reality, is nothing more than writing one step of the algorithm after another, the one that has been written first will be the one that is executed first.

Let's see an example: we want to read the radius of a circle, calculate its area and show the result to the user on the screen.

In pseudocode it would be:

number: radius, area; //Declaration of variables;


Write "give me the radius of the circle";

Read radius // assignment of the value of the variable radius by the user through the keyboard;

area = 3.14159 * radius; // we assign the value of the area variable with its formula;

Write "the area of ​​the circle is:" // EYE In the text IF WE CAN AND WE SHOULD PUT ACCENTS;

Write area; // shows us on the screen the value of the variable area resulting from the previous formula;


As you can see, the instructions are executed one after the other until reaching the end.

Selective structures

These structures are used to MAKE DECISIONS (which is why they are also called decision or alternative structures).

What you do is EVALUATE a condition, and then, depending on the result, you carry out one option or another.

Simple alternatives (IF conditional)

They are the known "if ... then". They are used in the following way: I want to evaluate a condition, and if it is met (that is, if it is true), then I will perform a series of steps.

An example

In pseudocode it would be:

numerical: number, root


show on screen "enter a number"

read number

Start YES

IF number> = 0 THEN: //> = 0 means greater than or equal to zero;

root = square_root (number)

display "the square root is:"

show on screen root

End yes


In all programming languages the SI conditional is written as follows.

if number = 0 {commands that the program will do if it meets the condition that the variable number is equal to 0}

That is, the word if followed by the condition and then, in brackets, what will be done if the condition is met.

Date update on 2021-03-31. Date published on 2021-03-31. Category: Computer class Author: Oscar olg Fuente: areatecnologia