[Gambas-user] Short-circuit evaluation question

Tobias Boege taboege at gmail.com
Fri Jan 26 17:18:50 CET 2018


On Fri, 26 Jan 2018, Gianluigi wrote:
> Hi Charlie,
> apologize me for the project and the question, all very confusing.
> 
> The question was on the short circuit.
> The NULL array is intended to demonstrate that short cirquitation does not
> work in the second IF block.
> I think it's due to the fact that the second IF starts with NOT.
> See the new attached project
> Thank you very much for your reply
> 

Short circuit evaluation works, but your code in the second case

  Dim ss As String[]
  If Not IsNull(ss) Or If ss.Count > 0 Then

requires a long circuit. ss *is* Null here, so "Not IsNull(ss)" will
be false, requiring the second condition to be evaluated, which gives
you an error.

As a general rule, whenever

  If Condition1 Or If Condition2

takes a short-circuit,

  If Not Condition1 Or If Condition3

will require a long one.

Regards,
Tobi

-- 
"There's an old saying: Don't change anything... ever!" -- Mr. Monk


More information about the User mailing list