Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8972839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:18:52+00:00 2026-06-15T18:18:52+00:00

Possible Duplicate: Should I always use the AndAlso and OrElse operators? In a practical

  • 0

Possible Duplicate:
Should I always use the AndAlso and OrElse operators?

In a practical implementation for all scenarios, the logical expression will return the same boolean value for both And and AndAlso,

why not we use always AndAlso and save the processing time for the next condition when the previous is false? In other words, Why And is still in use?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T18:18:53+00:00Added an answer on June 15, 2026 at 6:18 pm

    The And operator in VB.NET performs two jobs, it is both a logical and a mathematical operator. Early versions of Visual Basic did not distinguish between the two. By design, the language was designed to be easy-to-use and forcing Visual Basic programmers to learn the difference was something the language designers wanted to avoid.

    That worked pretty well, although it gave the language a few quirks. The value of True for example is not 1, like it is in many languages, it is -1. The value you get from CInt(True). Which allows ignoring the difference between the two uses of the operator, it still works well when an If() statement uses And when the left side is an Integer and the right side is a Boolean for example.

    But there’s a pretty specific problem with the And operator playing both roles. A common usage is to write a statement like this:

    If ix < array.Length And array(ix) <> 42 Then
       '' do something
    End If
    

    That’s a statement that will make your code crash with an IndexOutOfRangeException. What you meant is “if the index is out of bounds then don’t bother checking the array element”. That’s called “short-circuit evaluation”. But that’s not what the And operator does, it evaluates both the left and the right expressions. Like a mathematical version of the And operator must do.

    Short-circuit evaluation is important and has been around a long time. And universally adopted in the curly-brace languages, starting with C. And it finally got adopted in VB.NET as well, you write it like this to avoid the exception:

    If ix < array.Length AndAlso array(ix) <> 42 Then
       '' do something
    End If
    

    So to answer your question: Yes, always use AndAlso when you meant to use the logical version of the And operator. AndAlso is the logical version.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Should I always use accessors for instance variables in Objective-C? Lets suppose
Possible Duplicate: Java: Always override equals? should I override equals function for any class
Possible Duplicate: Should I use != or <> for not equal in TSQL? Behavior
Possible Duplicate: Should Usings be inside or outside the namespace sa1200 All using directives
Possible Duplicate: Why should I use templating system in PHP? I was just curious
Possible Duplicate: Should I use uint in C# for values that can’t be negative?
Possible Duplicate: Error handling in C code What return value should you use for
Possible Duplicate: Should I always prefer MySQL InnoDB over MyISAM? Under what conditions should
Possible Duplicate: Why should the implementation and the declaration of a template class be
Possible Duplicate: Should I use Elements or Attributes in XML? I have never been

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.