473,386 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Short circuiting by using AndAlso and OrElse

I am kind of confuse as to how these operators work:
AndAlso and OrElse

Anyone care to explain. Some examples would be great!
Jun 27 '08 #1
8 1240
On Apr 14, 2:39 am, Euvin <jceu...@uncc.eduwrote:
I am kind of confuse as to how these operators work:
AndAlso and OrElse

Anyone care to explain. Some examples would be great!
Euving,
Take a look at this link for a brief explanation:

http://visualbasic.about.com/od/usin...vbnetlogop.htm
Jun 27 '08 #2
A popular use of AndAlso would be something like this:

if ((anObj isnot Nothing) AndAlso (anObj.TheProperty = False)) then
' do some work
endif

With an ordinary "And" in the above, you would get an "Object not set..."
error in the second clause. The new syntax looks at the furst part, and
skips out when the object is not set.

OrElse is processed similarly. If the first part is true, then there is no
evaluation of the second part.

"Euvin" wrote:
I am kind of confuse as to how these operators work:
AndAlso and OrElse

Anyone care to explain. Some examples would be great!
Jun 27 '08 #3
Euvin wrote:
I am kind of confuse as to how these operators work:
AndAlso and OrElse

Anyone care to explain. Some examples would be great!
A simple way to look at it:

If TestA AndAlso TestB Then
DoSomething
End If

is equivalent to

If TestA Then
If TestB Then
DoSomething
End If
End If

For OrElse, you get

If TestA OrElse TestB Then
DoSomething
End If

being equivalent to

If TestA Then
DoSomething
ElseIf TestB Then
DoSomething
End If
Jun 27 '08 #4
Euvin,

The AndAlso and the OrElse are the same as in every orther language the And
and the Or.

A strong lobby from the VB6 side made that in VB this was choosen those two
above instead of the Or and the And.
Despite that less important things were changed with the introduction of
VB2001 this was a main option for the VB6 side.

The reason was that probably in 0,01% of all programs the OR and AND are in
VB as well used for boolean operations.

Something as AndBool and OrBool they called a breaking change.

The behaviour of And And Or in VB is too a little bit else because of this,
because everything is evaluated first.

Cor

Jun 27 '08 #5
Here the explanation of someone from the VB dev team ( Paul Vick software
architect of the VB Development team )

http://www.panopticoncentral.net/articles/919.aspx

and you wil see that

And & Or are used for bitwise comparisation

AndAlso & OrElse are used for logical comparisation

despite what people say or think it is clear that they took this idea from C
" like C where there are separate logical operators (|| &&) and bitwise
operators (| &)."

HTH

Michel
"Euvin" <jc*****@uncc.eduschreef in bericht
news:d6**********************************@2g2000hs n.googlegroups.com...
>I am kind of confuse as to how these operators work:
AndAlso and OrElse

Anyone care to explain. Some examples would be great!

Jun 27 '08 #6
"Euvin" <jc*****@uncc.eduschrieb:
>I am kind of confuse as to how these operators work:
AndAlso and OrElse

Place the caret on 'AndAlso' or 'OrElse' and press the F1 key in the IDE's
text editor.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Jun 27 '08 #7
Michel,

C is using || and &&.
The the shortcutted Or and And are much older: it was already in the first
versions of Cobol.

:-)

Cor

"Michel Posseth [MCP]" <MS**@posseth.comschreef in bericht
news:OM*************@TK2MSFTNGP05.phx.gbl...
Here the explanation of someone from the VB dev team ( Paul Vick software
architect of the VB Development team )

http://www.panopticoncentral.net/articles/919.aspx

and you wil see that

And & Or are used for bitwise comparisation

AndAlso & OrElse are used for logical comparisation

despite what people say or think it is clear that they took this idea from
C " like C where there are separate logical operators (|| &&) and bitwise
operators (| &)."

HTH

Michel
"Euvin" <jc*****@uncc.eduschreef in bericht
news:d6**********************************@2g2000hs n.googlegroups.com...
>>I am kind of confuse as to how these operators work:
AndAlso and OrElse

Anyone care to explain. Some examples would be great!

Jun 27 '08 #8
>>it was already in the first versions of Cobol.

Yes i know that we have just rewritten a production system from Cobol so i
have seen some familiair constructs in these sources , as we had to rewite
the system from printed out Cobol source

However my point is that from origin most MS developers are C proggers and
if you read most MS DEV blogs you read that they took ideas from there
background "C" and introduced it to VB

Michel
"Cor Ligthert[MVP]" <no************@planet.nlschreef in bericht
news:35**********************************@microsof t.com...
Michel,

C is using || and &&.
The the shortcutted Or and And are much older: it was already in the first
versions of Cobol.

:-)

Cor

"Michel Posseth [MCP]" <MS**@posseth.comschreef in bericht
news:OM*************@TK2MSFTNGP05.phx.gbl...
>Here the explanation of someone from the VB dev team ( Paul Vick
software architect of the VB Development team )

http://www.panopticoncentral.net/articles/919.aspx

and you wil see that

And & Or are used for bitwise comparisation

AndAlso & OrElse are used for logical comparisation

despite what people say or think it is clear that they took this idea
from C " like C where there are separate logical operators (|| &&) and
bitwise operators (| &)."

HTH

Michel
"Euvin" <jc*****@uncc.eduschreef in bericht
news:d6**********************************@2g2000h sn.googlegroups.com...
>>>I am kind of confuse as to how these operators work:
AndAlso and OrElse

Anyone care to explain. Some examples would be great!


Jun 27 '08 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: ram | last post by:
hi all, apart from readability, and not wanting the otherwise different statements to be assumed as one single loong statement what are the pros/cons of both snippets? i tried this out on a...
14
by: Jeremy | last post by:
Paul Vick posted this Blog (link below), "The Ballad of AndAlso and OrElse", and I noticed people were discussing this topic semi-regularly so I thought I would post the pseudo-official word of...
10
by: Mike Hale | last post by:
Is it better to use AndAlso and OrElse by default rather than the regual And & Or? MikeH
6
by: Raymond Lewallen | last post by:
I understand the differences between And and AndAlso and the differences between Or and OrElse. Under what circumstance would you NOT use short-circuiting when evaluating expressions? It seems to...
5
by: Phil Jones | last post by:
I'm just (as a matter of course) using AndAlso and OrElse statements to short circuit checking, even for nominal things like Boolean comparisons. I'm wondering, is that a good thing to do (for...
0
by: benfly08 | last post by:
Hi, guys. I'm using VB.NET to write an ASP page. I use a datagrid to display data from database. I have two types of items: Dry and Frozen. I want to put anchor to these two headers so that...
0
by: Work007 | last post by:
Hi. I really need help on how to use a value stored in a listbox. I have a form on which it has the following code. This form allows the user to add a value to the textbox which is on this page...
12
by: Al G | last post by:
Ok, so I've started to use it, and it is quicker. Now, why is it that "AND" doesn't already work this way? Al G
3
by: Siegfried Heintze | last post by:
Are there operators in C# that are the counterparts of "OrElse" and "AndAlso" that I can use when translating the following program from VB.NET to C#? Thanks, Siegfried Namespace vbtest...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.