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?
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:
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:
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.