OrElse and AndAlso

I actually just learned about this a few months ago.  I'm sure it's an old .NET technique for some of you out there, but it's one of the simplest things you can do to make your code just a little more efficient. 

Basically, if you have a simple if-then statement as follows:

If myInteger=4 And myString=“Hello” then
        CallFunction()
End If

then your program will check both myInteger AND myString to see if they match the required values, and then proceed.  If you change And to AndAlso, your program will first evaluate myInteger.  If it does indeed equal 4, THEN the code will look to myString to check whether or not it contains “hello”, before it considers running CallFunction().  If myInteger is not 4, the if-then block is exited, without ever checking in with myString

OrElse short-circuits Or statements in the same manner. 

It's a simple shortcut that is quickly applied across a large application, which makes your code ever so slightly more efficient. 

For more info, check out Mike Farnsworth's article on it.

Published Saturday, 12 Apr. 2008. 00:04

COMMENTS

   

Leave a Comment

Your Name (required):
Your Comment (required):
67.25.2
Please enter the code above in the box below without the dots:
Other Great Blogs
Bimeyen's Blog
Ndikum's Blog
Check this great idea on how to Send Great gifts to family in Cameroon. Click below. Lost of people talking about it and using it too...

SEARCH

GO

ARCHIVES