E
E
egyptForce2018-10-04 22:00:32
JavaScript
egyptForce, 2018-10-04 22:00:32

How is such a construction implemented in programming languages?

1. A || B
2. A && B
In the first case, it will be true if one of the two is true. In the second case, it will be true if both are true at the same time. With this, everything is clear, the school program.
Imagine that A and B are, for example, function calls that mutate somewhere, change something, etc. In the first case, function B will be executed only if function A returns false after its execution. Accordingly, in the second case, B will be executed if A returns true. This statement is true for javascript.
Now the actual question. Is this statement true for other languages? Is this behavior dependent on the PL or is it something fundamental and will work the same in any PL?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
eRKa, 2018-10-04
@egyptForce

What you are talking about is only true for dynamically typed languages ​​like javascript. There you can do something like this

var predicate = true;
var anyMethod = function() { ... }
if(predicate && anyMethod){ ... }

In C#, you can't afford this, where logical operators can only be applied to the bool type. In the case of C#, anyMethod would probably be a delegate. In C #, you have to write like this There is
no mother of specifications, each language has its own specification. But such languages ​​as C++, C#, Java javascript are considered C-like languages, i.e. in terms of syntax, they are a subset of the C language. Therefore, all these languages ​​can have syntax similarities and it may seem that this should be the case everywhere. But in other languages, the syntax for && and || may look different or it may not exist at all and only logical & and | remain.

A
ApeCoder, 2018-10-05
@ApeCoder

In C++, you can override these operators and then the arguments will be evaluated in full

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question