473,396 Members | 2,011 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,396 software developers and data experts.

If a() AND b() both ALWAYS execute?

Is this the default and expected behavior for vb.net?

'C' and 'C++' used to skip b() if a() was not true, because there was no
way the IF expression would ever be true.

For example, if you did something like:

If (NOT atEOF()) AND dataValueOK() Then
' process valid data here
ELSE

End if

will blow up in dataValueOK() as it's evaluated EVEN if atEOF() is TRUE.

Nov 20 '05 #1
9 1145

"PagCal" <pa****@runbox.com> wrote in message
news:uE**************@TK2MSFTNGP12.phx.gbl...
Is this the default and expected behavior for vb.net?

'C' and 'C++' used to skip b() if a() was not true, because there was no
way the IF expression would ever be true.

For example, if you did something like:

If (NOT atEOF()) AND dataValueOK() Then
' process valid data here
ELSE

End if

will blow up in dataValueOK() as it's evaluated EVEN if atEOF() is TRUE.


Yes, this is the way And works. VB.NET is the first VB to truly support
short-circuiting, which is what you're describing, but it requires new
keywords to do so: AndAlso and OrElse. And and Or still work the way they
always have, i.e., no short-circuiting.
Nov 20 '05 #2
PagCal,
Yes, that is the expected behavior for the "And" operator.

If you want to short circuit like C & C++ would, you need to use the
"AndAlso" operator.

Something like:
If (NOT atEOF()) AndAlso dataValueOK() Then
' process valid data here
ELSE

End if
Hope this helps
Jay

"PagCal" <pa****@runbox.com> wrote in message
news:uE**************@TK2MSFTNGP12.phx.gbl... Is this the default and expected behavior for vb.net?

'C' and 'C++' used to skip b() if a() was not true, because there was no
way the IF expression would ever be true.

For example, if you did something like:

If (NOT atEOF()) AND dataValueOK() Then
' process valid data here
ELSE

End if

will blow up in dataValueOK() as it's evaluated EVEN if atEOF() is TRUE.

Nov 20 '05 #3
* PagCal <pa****@runbox.com> scripsit:
Is this the default and expected behavior for vb.net?


Yes. 'And' is a binary operator in VB, and this will cause the binary
operation AND to be performed on the bits of the parts left and right to
the operator. I assume you are looking for the 'AndAlso' operator,
which is a logical operator.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #4
SA
This is an interesting explanation...

I thought And dubbed as both a binary operator and as a logical operator?
Which is why I visit this newsgroup...

Thanks,

--

Sven
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:2l************@uni-berlin.de...
* PagCal <pa****@runbox.com> scripsit:
Is this the default and expected behavior for vb.net?


Yes. 'And' is a binary operator in VB, and this will cause the binary
operation AND to be performed on the bits of the parts left and right to
the operator. I assume you are looking for the 'AndAlso' operator,
which is a logical operator.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 20 '05 #5
* "SA" <in*********@freemail.nl> scripsit:
This is an interesting explanation...

I thought And dubbed as both a binary operator and as a logical operator?


That's "true".

The binary representation of 'False' is 0000000000000000. By "ANDing"
something with 'False', it will remain false, because there is no bit
set in 'False'. By "ORing" something, the bits will be set if they are
set in the value that is "ORed" with 'False'. The result is treated as
'Boolean' again, so it can be used as condition in an 'If...Then'.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #6
What ever happened to the BitAnd, BitOr, etc. proposed early on?
Personally, I like the explicitness of differentiating between logical and
bitwise operators.
If I recall, FoxPro has quite an assortment of BITxxx operators.

Gerald

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:2l************@uni-berlin.de...
* "SA" <in*********@freemail.nl> scripsit:
This is an interesting explanation...

I thought And dubbed as both a binary operator and as a logical operator?


That's "true".

The binary representation of 'False' is 0000000000000000. By "ANDing"
something with 'False', it will remain false, because there is no bit
set in 'False'. By "ORing" something, the bits will be set if they are
set in the value that is "ORed" with 'False'. The result is treated as
'Boolean' again, so it can be used as condition in an 'If...Then'.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 20 '05 #7
* "Cablewizard" <Ca*********@Yahoo.com> scripsit:
What ever happened to the BitAnd, BitOr, etc. proposed early on?
They simply don't exist. In other words, 'Or', 'And', ... are bitwise
;-).
Personally, I like the explicitness of differentiating between logical and
bitwise operators.


I would have liked the 'Bit*' operators too, because in general you more
often use a logical 'And' than a bitwise 'And'.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #8
In article <2l************@uni-berlin.de>, Herfried K. Wagner [MVP] wrote:
* "Cablewizard" <Ca*********@Yahoo.com> scripsit:
What ever happened to the BitAnd, BitOr, etc. proposed early on?


They simply don't exist. In other words, 'Or', 'And', ... are bitwise
;-).
Personally, I like the explicitness of differentiating between logical and
bitwise operators.


I would have liked the 'Bit*' operators too, because in general you more
often use a logical 'And' than a bitwise 'And'.


It was those damn beta 2 rollbacks! I liked the Bit* stuff as well.
But, to many people complained about "broken" code when upgrading.

--
Tom Shelton [MVP]
Nov 20 '05 #9
Tom,

* Tom Shelton <to*@YOUKNOWTHEDRILLmtogden.com> scripsit:
What ever happened to the BitAnd, BitOr, etc. proposed early on?


They simply don't exist. In other words, 'Or', 'And', ... are bitwise
;-).
Personally, I like the explicitness of differentiating between logical and
bitwise operators.


I would have liked the 'Bit*' operators too, because in general you more
often use a logical 'And' than a bitwise 'And'.


It was those damn beta 2 rollbacks! I liked the Bit* stuff as well.
But, to many people complained about "broken" code when upgrading.


Consequently, a lot of upgraded code uses bitwise operators where using
them doesn't bring a benefit.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #10

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

Similar topics

26
by: TomB | last post by:
I have a function on an "included" page. For reasons unknown to me I frequently will get an error - to the effect that the function can't be found. If I hit refresh/F5 it loads the page just...
25
by: Mantorok Redgormor | last post by:
Finally, control is returned to the host environment. If the value of status is zero or EXIT_SUCCESS, an implementation-defined form of the status successful termination is returned. beyond this...
17
by: orekinbck | last post by:
Hi There Say I want to check if object1.Property1 is equal to a value, but object1 could be null. At the moment I have code like this: if (object1 != null) { if (object1.Property ==...
5
by: Haydnw | last post by:
Hi, I have the code below as code-behind for a page which displays two images. My problem is with the second bit of code, commented as " 'Portfolio image section". Basically, the SQL query gets...
8
by: arganx | last post by:
The conditional statement "if(j.... always executes regardless of what you enter. BOOL CALLBACK EnumWindowsProc(HWND hwnd,LPARAM lParam) { char buffer=""; GetWindowText(hwnd,buffer,256);...
0
by: Corey Wallis | last post by:
Dear All, I'm currently working on a project that needs to collect the output of the JHOVE application. More information about the application is available at this website: ...
5
by: alingsjtu | last post by:
Hello, every body. When execute dynamic generated multiple OPENQUERY statements (which linkes to DB2) in SQLServer, I always got SQL1040N The maximum number of applications is already connected...
8
by: flamesrock | last post by:
So, I was blazin' some mad chronix, as they say, and got on to thinking about Python. The question was, is the statement: time.time() < time.time() always true? Seems it should be false,...
3
by: Ed | last post by:
Hi, guys, I add some new projects. No source file, but only some copy operation in Post Event. The project is to do some file deployment for some third party library. When I compile the...
6
by: KDawg44 | last post by:
Hi, My responseXML is always null on my AJAX call. When I browse directly to the PHP script I am calling, the XML file shows up just fine. I have read that if a returned XML file is not...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.