Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shortcircuiting: OrElse combined with Or

If I have the following ...

a OrElse b 

... and a is True then clearly b is never evaluated. But if I add an Or, then what?

a OrElse b Or c

Does/should c get evaluated? And what if I put in some brackets?

Apologies if this is basic. Of course I can test for the answer myself but I can't find this question answered here or elsewhere. Lots of questions dealing with Or versus OrElse but nothing dealing with Or with OrElse

like image 799
hawbsl Avatar asked Sep 09 '10 14:09

hawbsl


People also ask

What is short-circuit evaluation in context of && and || operators?

Short-circuit evaluation means that when evaluating boolean expressions (logical AND and OR ) you can stop as soon as you find the first condition which satisfies or negates the expression.

Is OR a short-circuiting operator?

The || OR operator is also a short-circuit operator. Since OR evaluates to true when one or both of its operands are true , short-circuit evaluation stops with the first true . The OR operator comes in a non-short-circuit version as well: | (this is a single vertical bar.)

Why are short-circuit and && and short-circuit OR operators are fast in Java?

A short circuit happens because the result is clear even before the complete evaluation of the expression, and the result is returned. Short circuit evaluation avoids unnecessary work and leads to efficient processing.

What is the use of short-circuiting?

A short circuit (sometimes abbreviated to short or s/c) is an electrical circuit that allows a current to travel along an unintended path with no or very low electrical impedance.


1 Answers

OrElse short circuits between the left and right side parameters (only 2 parameters). So I would say that C will always be evaluated as you could treat this as (A OrElse B) Or C.

MSDN OrElse

like image 178
msarchet Avatar answered Oct 04 '22 22:10

msarchet