Wish - AndAlso / OrElse

joneden

Active Member
Licensed User
Longtime User
Could AndAlso and OrElse statements be added at some point.

Anyone that uses vb.net and doesn't use them should look into them - they can simplify conditional logic such as if statements considerably.

Regards,

Jon
 

joneden

Active Member
Licensed User
Longtime User
Hi Erel,

That's good news - I can ditch a few if statements now.

Many Thanks,

Jon
 

Roger Garstang

Well-Known Member
Licensed User
Longtime User
Never used them in VB, although I believe what you mean is Short Circuit Evaluation which B4A uses as Erel pointed out. Along those same line though- I would like to see something like an IIF or in C style languages- <Expression> ? <True Part> : <False Part>. Being able to have something inline would be great and would really improve my coding and not have so many IF blocks when all I need to do is output something in one line.
 

joneden

Active Member
Licensed User
Longtime User
Ah yes - I can never remember terminology for some reason :)

I know that in C# they are like B4A - turned on by default. No idea why VB.NET doesn't have it turned on for And and OR.

I agree about iif - would be a very useful addition.
 

COBRASoft

Active Member
Licensed User
Longtime User
VB.Net keeps the Basic way of thinking, which is not shortcut. Sometimes this can be handy that both parts of an AND or OR are evaluated instead of being shortcut.

E.g.: If FunctionA And FunctionB Then ... <- This way both functions are executed, no matter what the outcome of FunctionA is. In .Net I mainly use AndAlso and OrElse, but occasionaly, I use the 'old' way where needed :).

IIf is not that handy, because both parts are executed in .Net (most people don't know this). You can also use If() by which only the result is executed.

So, gimme an If() which executes only the result please...
 

joneden

Active Member
Licensed User
Longtime User
Try as I might I could never see that executing both would be useful unless it involves a function call where something else is done in addition to the comparison.

Yes I've been hit with the iif executing both functions before - I only ever use it to construct basic strings but find it very useful in that respect.
 

Jost aus Soest

Active Member
Licensed User
Longtime User
I would like to see something like an IIF or in C style languages- <Expression> ? <True Part> : <False Part>. Being able to have something inline would be great and would really improve my coding and not have so many IF blocks when all I need to do is output something in one line.

You mean something like this:
B4X:
Sub IIf(Condition As Boolean, Yes As Object, No As Object) As Object
   If Condition Then Return Yes Else Return No
End Sub
Sometimes it's really useful. Of course here is no short cut eval.
 

Roger Garstang

Well-Known Member
Licensed User
Longtime User
IIf is not that handy, because both parts are executed in .Net (most people don't know this).

I also program .Net (C#...mostly Win Mobile with a few Desktop Apps) and I'm not sure what you mean here. The Boolean condition is still executed like any other boolean condition and/or if you mean both the true and false outcome portions were executed I'd have a lot of issues in my apps. I also use the ?? operator which many don't know about and would be an interesting addition as well:

B4X:
myVar= otherVar ?? "myVar is set to this if otherVar is null"

You mean something like this:
B4X:
Sub IIf(Condition As Boolean, Yes As Object, No As Object) As Object
   If Condition Then Return Yes Else Return No
End Sub
Sometimes it's really useful. Of course here is no short cut eval.

Why no short circuit evaluation? Condition still is a boolean operation obeying the rules and honoring short circuit if it occurs. That is a nice model though, and I may use that until we get the functionality. Or do you mean that since the yes/no values are all passed to the function that they are executed to get their value if they are a sub/method/function?
 
Last edited:

COBRASoft

Active Member
Licensed User
Longtime User
C# handles this differently than Basic :). In Basic you have IIf and If, the last one acts like the C# equivalent. And yes, I was talking about the True and False part being evaluated with an IIf.
 
Top