Stopping procedure execution early using the End statement

The End statement terminates execution of the current procedure, and also execution of any procedure in the sequence of calls that called the current one.

The syntax is:

End [ returnCode ]

The optional returnCode is an integer expression. The script where this statement appears returns the value of this expression to the IBM® software application that executed the script. Refer to the product documentation to determine whether the product expects a return value when the End statement is executed. If no return code is expected, do not specify one with the End statement.

In this example, the sub DoTimer is called, which then calls the sub ElapsedTime. When the End statement in ElapsedTime is executed, execution continues at the Print statement following the DoTimer call.

' Compute the time to run some number of iterations of a For
' loop, and the time to execute the ElapsedTime sub.
Dim anInt As String
Public startSub As Single, startLoop As Single
Public counter As Long
Sub ElapsedTime
   ' If 0 or negative number of iterations is specified,
   ' print a message and end execution.
   If counter& <= 0 Then
      Print "Number of iterations must be >0"
      End                        ' End execution
   End If
   startLoop! = Timer()
   For doCount& = 1 To counter&
   Next
   Print Timer() - startLoop! "seconds to run" counter& _
     "iterations"
End Sub
Sub DoTimer
   ' DoTimer calls ElapsedTime and reports the result.
   anInt$ = InputBox$("Enter a whole number:")
   counter& = CLng(anInt$)
   startSub! = Timer()
   Call ElapsedTime()
   ' This Print statement will not be executed if the End
   ' statement in sub ElapsedTime was executed.
   Print Timer() - startSub! "seconds for ElapsedTime sub call"
End Sub
Call DoTimer()
' Sample output, for 5000 iterations requested by user:
' .109375 seconds to run 5000 iterations
' .1601563 seconds for ElapsedTime sub call
' Output for -1000 iterations requested by user:
' Number of iterations must be >0