Logical operators perform conditional and, or, and not operations. Some languages support both binary logical operators that link two and unary logical operators negate (make opposite) the truth value of its argument. Finally, some languages short circuit logic. For example, with this or that, if this is an expression returning true, then that is never executed.
ASP Classic Logical Operators
Same as VB. ASP Classic logical operators:
and
and, as in this and that
or
or, as in this or that
Not
Not, as in Not This
ASP Classic never short circuits. Given the expression this or that as well as this and that, if this evaluates to false, then that is still executed.
Syntax Example:
'Given expressions a, b, c, and d:
If Not (a and b) and (c or d) Then
'Do something.
End If
ASP Classic Short Circuting Example:
In the following example, if ASP Classic supported short circuting, the That function would never execute. It's interesting to note that VB.Net has introduced two new operators to support short cicuiting: AndAlso and OrElse for use when you code in ASP.Net.
<body> <h1>Short Circuting</h1> <% Function This() Response.Write("<br>The This function executed.") This = False End Function
Function That() Response.Write("<br>The That function executed!") That = True End Function
'Notice both the This and That functions execute 'even though the This Function returned False. If This And That Then Response.Write("<br>Both are true.") End If %> </body>
The following are practice certification questions with answers highlighted. These questions were prepared by Mike Prestwood and are intended to stress an important aspect of this KB post. All our practice questions are intended to prepare you generally for passing any certification test as well as prepare you for professional work.