Last post Jul 08, 2015 09:24 AM by PatriceSc
Jul 07, 2015 03:58 AM|fazioliamboina|LINK
i have a simple question which is (strange enough) nowhere to be found on Search engines..
please look at the code below
If True and True orelse True Then
What i dont understand, is why the third boolean is evaluated. because it stops my application to function properly.
i need a short circuit, that does this job :
- if the first and the second booleans both return True.. THEN I dont want the third to be evaluated and then run the code inside of the block.
- But if any of those first two booleans return False, i want want the third one to evaluate and decide whether running the code inside of the block or not.
- the third Boolean is actually a code that generates an error upon execution if any of the first two booleans are true. and therefore i dont even want it executed in that case.
I am irritated by subbing If blocks into each others and bothering with tons of Else statements.
Jul 07, 2015 04:13 AM|Mikesdotnetting|LINK
If (True and True) OrElse True Then
Jul 07, 2015 05:38 PM|David Anton|LINK
What is your actual 'If' statement?
'And' does not short-circuit, but 'AndAlso' does. ('And' is normally intended for bitwise operations, not logical conditions).
Jul 08, 2015 08:36 AM|fazioliamboina|LINK
Lets say i am using this code :
If true or (true Orelse new list(of string)(1) = "Hello") Then
In this Case, even while both first conditions are TRUE, the third condition still causes an index exception. I made this exception myself to proove it was stil evaluated.
Jul 08, 2015 09:24 AM|PatriceSc|LINK
This code doesn't compile. What is the exact code you tried and which exception do you have? I tried:
If True Or (True OrElse New List(Of String)().ElementAt(100) = "Hello") Then
which works as expected (ie runs fine and if using Or instead I've got an ArgumentOutOfRangeException)