I don't believe VBScript short-circuits logical operators.
I'm not sure whether JScript does either, but this question and the
previous one have prompted me to say this anyway: if you are already
familiar with ALGOL-derived languages like C or Java, you might find
that JScript fits your mental model better.
On 3/26/2012 5:11 PM, David Helkenn wrote:
Hello,
I am curious to learn if VBS has any support for short-circuit
operators, as in some higher level languages? The VBS reference is
silent on this point. For example, the expression:
if (A and B) or (C and D) then
...
end if
can be 'short-circuit' to the then portion if A is true -- *WITHOUT*
evaluating B, C, or D. This can come in very handy if verifying
something is in range of an array index *BEFORE* evaluating B, C, or D
which may depend upon a valid index variable. You can also see that if
this expression must be split apart into their own if statements, the
code can become very complicated, duplicated, and error prone in a
hurry. If I have to break it apart, I think I'd opt for boolean
functions (more than one would be needed) to use in the expression.
but, shortCircuit operators are a lot more convenient.
Thanks!
David Helkenn