Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Quick if question

Status
Not open for further replies.

AdaHacker

Programmer
Sep 6, 2001
392
US
I was wondering, does VB have any way to support short circuit evaluation of if statements, or any other Boolean statements for that matter? I've never seen any, and I was just wondering if it can be done. It's not particularly important, but it would a lot cleaner to write
if x=a and not b and c then ...
when b and c are not necessarily well defined than it is to use a whole bunch of nested if blocks. I know that in Ada95, there is the standard AND as well as an AND THEN, which is a short circuit version. Does VB have anything comparable, or do I just have to live with ugly code?
 
Go for the ugly. I used ADA for a bit, thought it was weird.

It often makes it much easier to read if you do
l1 = a and not b
l2 = c and not e

then use l1 and l2 if the if's
Peter Meachem
peter@accuflight.com
 
Yeah, I could use that, and in some cases I do. It's just that, to me, it's a lot clearer to say
If Not IsNull(a) And a = b Then ...
than it is to add the extra line and have essentially the same conditional. I guess it's just a matter of personal preference. Short circuit evaluation may have some dangers, but, in my opinion, it's often more intuitive and easier to read. I was just wondering if there's a way to do it.
 
VB6 does full evaluation. IOW, it goes through the entire statement (calling functions if needed) before determining the truth or false-ness of the condition.

VB.NET does short-circuit evaluation. IOW, when it determines the condition is unquestionably true or false, it abandons evaluating the rest of the statement. This will mean that some functions might never be called.

I expect this will trip up more than one developer making the switch. :)

Chip H.


 
I used to use a species of Fortran that did that. Problem was it didn't always do it properly which caused a lot of difficult to fix problems. Peter Meachem
peter@accuflight.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top