Terminology - What is the difference between statement and statement?

Asked

Viewed 244 times

3

What would be the difference between them?

Instruction would be a line of code representing certain commands/actions passed to the computer to execute.

Statement, following logic, would be a kind of instruction? Since, as I understand it, it would be an instruction to declare something (a variable statement statement, for example).

Is there any difference between these two words?

I thank you all!

  • Are you only interested in Python-restricted responses specifically or do you want something broader to address how statements and statements are handled in most programming languages (which treat them very similarly)? In any case, my reply should address both cases.

  • Can you say in English the meaning of these words? Because I think you’re talking about statement and not declaration, which gives a completely different answer. In Brazil we misread these terms.

2 answers

2


Declaration is when you declare a variable, function, method, class or similar thing.

Instruction is that where you instruct the program to perform a certain action.

Statements are usually not considered instructions because they say something that explains to the compiler or interpreter where certain data is recorded or what format it is. It’s not usually something to be directly executed that will have some sort of effect somewhere.

The instructions are things to be executed at certain times and that have some kind of effect: change values of variables, allocate or (depending on the language) displace memory, modify the state of the execution stack, perform some type of input or output, etc. Statements do not do this, as they are not executable, they only give names to some things.

It is true that you may have something like this depending on the programming language:

var x = 123;

In that case, the declaration shall be var x and the initialization is the x = 123. Initialization is an assignment type that is an instruction type. In this case, this line contains a statement and an instruction. They could be separated with this equivalent:

var x;
x = 123;

In Python specifically, the use of class MinhaClasse: is a class statement, while def meu_metodo(): is a method statement. Python does not require the declaration of variables in other cases, but these are required in other programming languages, especially those that have static typing, such as C, C++, Java, C#, Pascal, Delphi, Rust and many others.

  • 1

    I appreciate the help and the time. Now I understand the 2 forms well. They were not very well explained in my mind, but now I understood well. I thank Victor!

0

The question has Python as tag, but the terminology is, in general, applicable to all programming languages.

Instruction: ask to do something or tell how to do it.

Statement: pass, change or create information.

The second may be contained in the first, since declaring something is nevertheless an instruction, although it does not cause any immediate action.

When writing x = true I am declaring to the program that now the variable x is true, and I’m also instructing the program to treat this variable in this way.

On the other hand, an instruction itself is like an "order" that the code tells the program to do something, i.e., perform an action or a condition, most of the time, according to the statements that have been made.

A simple example would be:

x = 1; // declaração
alert(x+10); // instrução

Another example of instruction would be:

if x == 1 then x = x+10

I’m instructing the program that if x is equal to 1, it should be increased with more 10 in its value.

The difference between one term and another is that one is passive, only declares information, while the other executes this information or actions within the program.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.