How to write a pseudocode?

I was reading about algorithms, but every algorithm I read was written in some unknown or non-invented language, but in a way I could understand what was written there.

I read about the Portugol , a" language " written in Portuguese that was made only to be interpreted by the human being, that would be a Hello World:

Algoritmo "OlaMundo"
var
inicio
Escreval("Olá, Mundo!")
Fimalgoritmo

In this code above, I don't understand what this var lost in the middle of the way is, and it caused me some confusion.

My question is: how to correctly write a pseudocode, so that all programmers can understand what I'm trying to interpret? Is there a syntax defined for this? Can I write as I please, in such a way that I can understand?

Author: CypherPotato, 2017-08-03

3 answers

As far as I know, there is no rule to write a pseudocode, so there is no correct way to write it, it should only be written in a simple way, so that anyone with minimal knowledge in programming can understand it.

Note that even using conventions of a normal programming language, the pseudocode is intended solely for human reading .

In Wikipedia we have the following definition:

Pseudocode is a generic way of writing an algorithm, using a simple language (native to the one who writes it, in order to be understood by anyone) without the need to know the syntax of any programming language.

With respect to the code snippet written in portugol, var identifies the section for declaring the variables that the program will use. In the example in question, var could be omitted without any problem, the code compiles normally in Visualg .

 12
Author: Mathiasfc, 2017-08-03 12:07:18

Pseudo: "prefix used in Word formation to express falsehood or similarity".

A pseudocode mimics a real code, but it is not. It is a representation of an algorithm,which in turn : "... it is a finite sequence of well-defined and unambiguous instructions...".

Everyone can write their own pseudo-code for their own purpose, but here we are talking about an algorithm that tries to imitate a program that will be run by a X interpreter / compiler, which has its own syntax and semantics rule to define the actions to be performed.

In the example you put we could translate from the pseudo-code (Portugol), into the Portuguese language like this:

Algoritmo "OlaMundo"{Define o nome do algorítimo como OlaMundo}
var{palavra chave para declarar uma ou mais variáveis nesse caso está vazio é desnecessário e confunde mesmo, se o VisualG precisar disso vazio eu vejo como erro}
inicio{palavra chave para marcar o inicio do algorítimo}
Escreval("Olá, Mundo!"){Escreva na tela Olá, Mundo!}
Fimalgoritmo{palavra chave para marcar o fim do algorítimo}

The actual algorithm in PHP for example would be:

<?php
$variavel = "Olá, Mundo!";//Atribuo a variável uma string Olá, Mundo! 
echo $variavel;//echo é o comando que emite a string passada como argumento
?>

Every language has its documentation, containing its rules.

The VisualG is based on Portugol, see its documentation.

 10
Author: MagicHat, 2017-08-03 12:26:24

Let's go to some definitions before actually answering.

Second Wikipedia :

Pseudocode is a generic way of writing an algorithm, using a simple language (native to the one who writes it, in order to to be understood by anyone) without the need to know the syntax of no programming language.

An example used in educational institutions, is the compiler Visualg , which facilitates the illustration of an algorithm, so that all programmers can understand them (regardless of the language they use).

In my time I learned in Pascal, which in the case is, as if it were the portugol of the English language that closely resemble a pseudocode.

Pascal:

program OlaMundo;
begin
 WriteLn('Olá, Mundo!');
end.

Visualg:

Algoritmo "OlaMundo"
inicio
Escreval("Olá, Mundo!")
Fimalgoritmo

The example I posted I believe is in visualg, and adopts var, for variable declaration, because visualg needs to some way to interpret to be able to compile, but if it is pseudocode, not compilable, the purpose is to understand what is trying to be transmitted, another example:

INÍCIO
VARIÁVEIS
S,C,I,A,MD:Real;
S ← 0;
C ← 0;
PARA I de 1 ATÉ 10 FAÇA PASSO 1
    Escreva "Digite um número: ";
    LEIA A;
    SE A ≥ 0 ENTÃO
         S ← S + A;
         C ← C + 1;
    FIM SE;
FIM PARA;
MD ← S / C;
ESCREVER ("A média é: ", MD);
FIM

Conclusion:
So, no matter what syntax you are going to use to write, with a standard Minin, and as long as it is possible for the receiver to understand what you want to say, it is valid.

 8
Author: David, 2019-07-02 12:08:52