Revision [13347]

This is an old revision of KeyPgReturn made by JeffMarshall on 2008-05-08 07:43:44.



Control flow statement to return from a procedure or KeyPgGosub Gosub.

Return [ expression ]
Return [ label ]

Return is used to return from a procedure or return from a gosub KeyPgGosub Gosub.
Because KeyPgReturn Return could mean return-from-gosub or return-from-procedure, KeyPgOptiongosub Option Gosub and KeyPgOptionnogosub Option Nogosub can be used to enable and disable KeyPgGosub Gosub support. When KeyPgGosub Gosub support is disabled, KeyPgReturn Return is then recognized as return-from-procedure. When KeyPgGosub Gosub support is enabled, KeyPgReturn Return is then recognized as return-from-gosub.
Return (from procedure) is used inside a procedure to exit the procedure possibly with a return value. A KeyPgSub Sub cannot specify a return return value. In a KeyPgFunction Function, Return must specify its return value. Return expression is equivalent to the Function = expression : KeyPgExit Exit Function idiom.
Return (from gosub) is used to return control back to the statement immediately following a previous KeyPgGosub Gosub call. When used in combination with KeyPgGosub Gosub, no return value can be specified. If the optional label is specified, execution continues at the specified label. If no KeyPgGosub Gosub was made, a runtime error is generated, and execution continues immediately after Return.
A KeyPgGosub Gosub should always have a matching Return statement. However, if Return (from gosub) is used where no KeyPgGosub Gosub was made, a run-time error is generated.

'' Compile with -lang qb
Print "Let's Gosub!"
GoSub MyGosub
Print "Back from Gosub!"

Print "In Gosub!"

Type rational_number                   '' simple rational number type
   numerator As Integer
   denominator As Integer
End Type

Type rational As rational_number       '' type alias for clearer code

'' multiplies two rational types (note: r1 remains unchanged due to the BYVAL option)
Function rational_multiply( r1 As rational, r2 As rational ) As rational

   r1.numerator *= r2.numerator        '' multiply the divisors ...
   r1.denominator *= r2.denominator
   Return r1                           '' ... and return the rational

End Function

Dim As rational r1 = ( 6, 105 )        '' define some rationals r1 and r2
Dim As rational r2 = ( 70, 4 )
Dim As rational r3

r3 = rational_multiply( r1, r2 )       '' multiply and store the result in r3

'' display the expression (using STR to eliminate leading space when printing numeric types)
Print Str( r1.numerator ) ; "/" ; Str( r1.denominator ) ; " * " ;
Print Str( r2.numerator ) ; "/" ; Str( r2.denominator ) ; " = " ;
Print Str( r3.numerator ) ; "/" ; Str( r3.denominator )

End 0

Dialect Differences:
Differences from QB:
See also:
Back to Control Flow
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki phatcode