I.T. Discussion Community!
-Collapse +Expand
ASP Classic
Search ASP Classic Group:

Advanced
-Collapse +Expand ASP Classic Store

Prestwood eMagazine

May Edition
Subscribe now! It's Free!
Enter your email:

   ► KBWebsite Scri...ASP ClassicLanguage Basics   Print This     
  From the May 2014 Issue of Prestwood eMag
 
ASP Classic Language Basics:
ASP Classic Logical Operators (and, or, not)
 
Posted 9 years ago on 2/11/2009 and updated 9/15/2009
ASP Classic Code Snippet:
 A flashcard from our ASP Classic Flashcards Library
 A code snippet from our ASP Classic Code Snippets Page

KB101891



Languages Focus: Logical Operators

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.

<%@LANGUAGE='VbScript'%>
<%Option Explicit%>
<html>
<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>
</html>

More Info


Comments

0 Comments.
Share a thought or comment...
 
Write a Comment...
...
Sign in...

If you are a member, Sign In. Or, you can Create a Free account now.


Anonymous Post (text-only, no HTML):

Enter your name and security key.

Your Name:
Security key = P1271A1
Enter key:
Code Contributed By Mike Prestwood:

Mike Prestwood is a drummer, an author, and creator of the PrestwoodBoards online community. He is the President & CEO of Prestwood IT Solutions. Prestwood IT provides Coding, Website, and Computer Tech services. Mike has authored 6 computer books and over 1,200 articles. As a drummer, he maintains play-drums.com and has authored 3 drum books. If you have a project you wish to discuss with Mike, you can send him a private message through his PrestwoodBoards home page or call him 9AM to 4PM PST at 916-726-5675 x205.

Visit Profile


Linked Certification Question(s)

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.

Beginner

1 Beginner Level Question

Question #1: True or False?

Given the following code, will True or False be written?

Dim a, b, c, d
 
a = True
b = True
c = True
d = False 
 
If Not (a And b) And (c Or d) Then
  Response.Write("True")
Else
  Response.Write("False")
End If
Answer:
  • True
  • False
  • Intermediate

    1 Intermediate Level Question

    Question #2: Yes or No?

    Given the following two functions:

    Function This()
        This = False
    End Function
     
    Function That()
        That = True
    End Function

     

    Will the That function in the following code execute?

    If This And That Then
      Response.Write("<br>hello.")
    End If
    Answer:
  • Yes
  • No

  •  KB Article #101891 Counter
    21359
    Since 2/11/2009
    -
       Contact Us!
     
    PrestwoodBoards.com was developed and is maintainted by me. Do you have a question or suggestion? Do you see a problem? Contact me now. My goal is to build an ad-free and spam-free source of I.T. information with many contributers (ok to promote your website/company in your bio). Yes, my company Prestwood IT Solutions is mentioned in my bio which shows with every post, but you can contribute and promote your pet project too!

    2,017 People Online Now!!  
    Sign In to see who's online now!  Not a member? Join now. It's free!
    Show more stats...


    ©1995-2018 PrestwoodBoards  [Security & Privacy]
    Professional IT Services: Coding | Websites | Computer Tech