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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Exiting an If statement

Status
Not open for further replies.

ninelgorb

Programmer
Mar 7, 2005
111
US
I know there is an EXIT for a Do, For, etc Loops, but is there something to exit an IF statement?

Thanks,
Ninel
 
Errr. ?

if/then statement is not a loop so if the expression if false it exits...

If <Expression> Then
' code for true value
Else
' code for false
End If
 
err, why not block if the remainder?

Code:
if Condition1 then
  'do thing

  if Condition2 then
    'do other thing
  end if
end if

Or, you can throw an exception. I use this if I'm validating data before running a block of code:

Code:
try
  'do thing

  if NoDataFound then
    dim excNoData as New Exception("No data found")
    throw excNoData
  end if

  'do other thing

catch exc as exception
  'handle exception
end try

And finally, yes, the GOTO statement still exists. But I am fundamentally opposed to it's continued existance, so I will not go into it.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
That being my point.

If the expression is true you proceed to process the code.

However, if further in your code you come across a reason for 'exiting' the IF, well, then you use another IF. This gives you the option to process or not whenever / wherever you want.

Dale
 
orelse andalso could come in handy in some cases when evaluating :D

- - - - - - - - - - - - - - - - - -
Im three apples high, Im blue, and i most certainly like that cold beer that should be every mans right after a hard days work!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top