U
U
Urukhayy2015-05-10 12:42:31
Programming
Urukhayy, 2015-05-10 12:42:31

In the "&&" check, will the second part fail if the first part is false?

In the "&&" check, will the second part fail if the first part is false?
if(a ==1 && b == 2)
If a is false, then b will not be executed?

Answer the question

In order to leave comments, you need to log in

5 answer(s)
R
Rsa97, 2015-05-10
@Rsa97

Depends on the programming language. For example, VisualBasic has two operators, And and AndAlso. And always evaluates both arguments, AndAlso evaluates the second argument only if the first one is true.

O
olexandr7, 2015-05-10
@olexandr7

Naturally

M
mamkaololosha, 2015-05-10
@mamkaololosha

Yes. Have you ever seen the design?
if(Obj != null && Obj.field != null) { }

Y
Yaroslav, 2015-05-10
@torwig

Yes. In C+, this is the so-called "short scheme". If the result of the first part allows you to unambiguously obtain the result of the entire expression, the rest of the expression is not calculated. The situation is the same with the || operator. Rumor has it that if you override these operators, then the "shortcut" won't work.

P
Power, 2015-05-11
@Power

Here is a general description of the principle and how it works in different languages: Short-circuit evaluation .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question