Go to: Articles List

Using the Exit statement

     Using the Exit statement you can force the flow of your program to exit the current set of logic it is in. An example of when you might want to do this is when you have a few nested if statements. Once you are in the if statements you check a certain condition and find it to be false. At this point you want to flow of your program to exit out of the current sub routine. With the Exit statement you can do this.

Syntax:

Exit LogicToExit

LogicToExit can be Do, For, Sub, or Function.

Example:

For i = 1 to 50
     If i = 10 Then
         Response.Write("Exiting For loop...")
         Exit For
     End If
Next

Result:
This code will loop through until i equals 10, then it will print "Exiting For loop..." and exit the loop.