Logo of Computer Classes

Programming fundamentals to start programming

A flow chart is a graphical representation of the algorithm. We express the steps of the algorithm by means of a scheme with established symbols.

A flow chart should provide clear, orderly and concise information on all the steps to be followed.

Let's see an example:

An algorithm to cook an egg for someone else would be:

  • I ask if you want the fried egg.
  • If he says yes, I cold it, if he says no, I do it boiled.
  • Once cooked, I ask him if he wants salt in the egg.
  • If he tells me I don't serve it on the Plate. If you tell me if I make it salt and then I serve it on the plate.

Now that we know all the steps, using the algorithm, we can make a diagram with these steps to follow.

This scheme will be the Flow Chart.

If one has experience, one can do without the written algorithm, but we will always have to keep it in mind to make the flow diagram without making mistakes.

As we will focus more on pseudocode, we will not talk more about flowcharts.

If you want to learn how to make flow charts we recommend this link: flow charts.

The Pseudocode

The pseudocode is a way of writing the steps, but in the closest way to the programming language that we are going to use, it is like a false language, but in our language, in human language.

One of the biggest difficulties faced by Spanish speakers who start programming is the language.

That is why it is good to use pseudocode, something like a false programming language in Spanish, which helps to assimilate basic ideas more easily.

For example, if we want to write something on the screen, in pseudocode we could put:

Write "Hello" or Write 20 + 30.

We can also use:

display "Hello"

We could really write the pseudocode as we wanted, since it is not really the program itself, it is only a help to later carry out the program through the programming language that we use, yes, it is of great help, so much so that it is essential.

But even if we can write it anyway, most programmers tend to use a common vocabulary.

This vocabulary will be the one we see here.

Remember that pseudo-code for a programmer is essential.

If you know how to make the pseudo-code of the program, transferring it to any programming language is very simple, you will only have to learn the commands equivalent to the instructions in pseudo-code.

Also, most languages ​​use practically the same commands in their language.

Let's continue talking a little more about the pseudocode.

To specify the beginning and end of the program we will put:

Start

Here would go the program in pseudocode

The end

Another widely used way would be:

Process NameOfProgram

Here would go the program in pseudocode

EndProcess

The 3 commands that we will use the most in pseudocode are:

Write -> Write the text that we put in parentheses on the screen or you can also write the value of a variable on the screen.

This instruction in almost all programs is usually written with the word write or document.write ('Hello') ;.

Read Age- -> reads us from what the user marks from the keyboard and saves the value.

For example, within a variable, in this case the Age variable (later we will see what variables are).

In real programming, the input instruction is usually used.

Calculate 3 x 5 -> Calculate values

Having the pseudocode or the Flow Diagram we have it very easy, since it is easily translatable into any programming language.

As we progress through the topic, you will see examples of pseudocode.

Now we are going to start with the interesting, we are going to start learning to program.

Comments

Putting comments about what we are doing is very useful, especially when it comes time to review the program, if not, more than once we will find ourselves saying, what was this doing here?

It costs nothing to document the program and it will save us headaches. The rule that is followed in all programs is to put // in front of the comments, to identify them:

// This will be a comment and will not do anything in the program

We will also post comments during the explanations.

The variables

A variable is like a box where we put things (data).

We can change these data, now I enter a 3, now I remove it and enter a 5.

A variable has a name, which can be a letter, a word, multiple words joined by the underscore, or multiple words without separating but the first letter of each word in uppercase.

Example .: LivesLost, lifeLost, Lives_Lost.

Be careful, uppercase and lowercase letters are very important in variables, it is not the same variable number as Number, they are two different.

BEWARE you cannot put accents in the name of the variables either.

The variables also have a value that is what is inside it (in the box) at that moment and that can vary as the program develops, that is why it is called a variable.

A variable depending on its value can be numeric, if it can only have a numeric value, text, if it can only contain text (letter, word or phrase also called string).

In text variables, their value (the text) must be enclosed in quotation marks, to differentiate that the text is text and is not the name of another variable.

For example lives = "Five" or lives = "5". In both cases the value is a text, never the value of 5.

Numeric ones do not have quotes in their value. For example: lives = 5.

In this case, its value is the number 5.

There are other variables called Boolean that can only have two true or false values.

Usually true can be substituted for the value 1 and false for 0.

Let's look at some examples of the types of variables:

Age = 3; // numeric variable.

Note that this in bold is a comment.

VariableDeTexto = "I am 14 years old"; // notice that it goes in quotes.

VariableNumerica = Age + 2; // its value is the value of the variable Age (numeric) +2; in this case it would be = 5 (3 + 2).

Boolean variable = true; in this case it would be of value 1

Have you noticed that we have put a semicolon (;) when finishing defining each variable?

In programming, whenever an instruction or group of instructions is finished, put ";" to tell the program that we go to a different instruction.

But let's get on with the variables.

In some programming languages, it is normal to declare variables at the beginning of a program.

Declare is nothing more than saying "look, I want three variables, and I want one to be called First Name, another Age and another Last Name".

In addition, you have to specify what type of variable it is when declaring it (not in all languages).

The declaration of variables is usually done at the beginning of the program, so it is important to know how many variables we are going to use before writing our program.

Let's see an example:

VariableNumerica: Age; // We declare the numeric variables.

VariableText: Name, Surname; // We declare the text variables.

Note: In most programs, variables are declared by putting "var" in front of them and giving them an initial value:

var Age = 15; var Text = "Hello", etc.

From this moment on, you can put its value in any part of the program.

Age = 5;

Name = "Juan";

Surname = "Rodriguez"

Then you can change its value, within the program, as many times as you want.

In programs that do not need to declare the type of variables, we could start the program simply by entering the initial values ​​of the variables or by setting the variables with their initial values ​​during the development of the program.

If a value does not have quotes, the program understands that it is numeric directly.

This last case is the easiest to start with, as a variable arises we put it with its initial value directly in whatever part of the program it is.

We can add, subtract, multiply, divide and do any type of mathematical operation with the variables.

number: Pepe, Mari, Juan // We declare the variables that we will use;

Pepe = 2;

Mari = 3;

Juan = Pepe + Mari; // Juan now has the numerical value of 5.

There are variables already defined by the programming language that we use, and whose name we cannot give to any of the ones we define.

We can use them but just as the language defined them.

For example, in many languages mouse_x is the variable that has the value of the x position of the mouse at all times, hspeed is the horizontal speed, etc.

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