Return

From REALbasicWiki

Jump to: navigation, search

The Return statement tells a method to return control of execution to the caller of the method. If the method has a return type (i.e. is a function), then the Return keyword must be followed by a return value of the return type declared by the function. If the method is a subroutine, then the Return keyword cannot be followed by anything.


Sub SubroutineExample()
  return
End Sub
Function FunctionExample() as String
  return "foo"
End Function

Return can be called from within any control structure to end execution of the method. For example:

Sub AnotherExample(w as Window)
  if w is nil then
    return
  end if

  //proceed with main body of code
End Sub


Note that Return returns immediately. In particular, code in a Finally block will not be executed if you return from the main body or an Exception block. Here is a simple example that you can run to see the behavior.

Sub Test()
  return

Finally
  MsgBox "Finally"
End Sub
Personal tools
related