vb.net elseif

These questions are about using elseif in visual basic.net.

1.  Is there any difference between elseif and else if ?
2.  If I have elseif (conditionA and conditionB) is it possible that conditionB is tested in the case that conditionA is false?  For example, if the testing of conditionB will cause a runtime error in the case that conditionA is false is it possible for this elseif statement to cause a runtime error?  Ada has a if (conditionA && conditionB) statement that will insure that the second condition is never tested if the first fails.  Does vb.net have anything like this?

santaspores1Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Imran Javed ZiaConsultant Software Engineer - .NET ArchitectCommented:

1. ElseIf is in vb.net and else if is in c#
2. you have to use short circuit and AndAlso insteat of simple and in c# && is by default short circuit (conditionA AndAlso conditionB) instead of (conditionA and conditionB). by using AndAlso b will not be executed if a is false
0
Éric MoreauSenior .Net ConsultantCommented:
1.  Is there any difference between elseif and else if ?

Yes. the "else if" syntax starts a brand new branch with its own conditions. It becomes a nested if (instead of another condition on the same if statement).

2.  If I have elseif (conditionA and conditionB) is it possible that conditionB is tested in the case that conditionA is false?  For example, if the testing of conditionB will cause a runtime error in the case that conditionA is false is it possible for this elseif statement to cause a runtime error?  Ada has a if (conditionA && conditionB) statement that will insure that the second condition is never tested if the first fails.  Does vb.net have anything like this?

Yes. Instead of And you can use AndAlso which will do the short-circuiting (same for Or/OrElse)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
santaspores1Author Commented:
1.  vb.net allows both elseif and else if... so do they behave in exactly the same way?
2.  Yes... short circuit is what I was looking for - thanks!  Just to be sure... in vb.net:
if (stringA.text.length > 1 AndAlso conditionB) Then
if conditionB would cause a runtime error if stringA were null... this conditional statement will still work... because conditionB will never be tested unless conditionA is evaluated as True FIRST?
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

santaspores1Author Commented:
Thank you both - I appreciate the help!
0
Éric MoreauSenior .Net ConsultantCommented:
>>because conditionB will never be tested unless conditionA is evaluated as True FIRST?

Right
0
khan_webguruCommented:
If stringA.text.length > 1 And conditionB  Then

End If

this means both conditions should be true than this block will run.

Thanks,
0
khan_webguruCommented:
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Server 2003

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.