### Revision history for KeyPgReturn

No Differences

#### Revision [22343]

Edited on 2018-07-15 01:58:51 by fxm [Clarify the use of Return in a Sub versus a Function]##### Additions:

##**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. ##**Return**## is roughly equivalent to the ##[[KeyPgExit|Exit]] Sub## idiom.

- In a ##[[KeyPgFunction|Function]]##, ##**Return**## must specify its return value. ##**Return** //expression//## is roughly equivalent to the ##Function = //expression// : [[KeyPgExit|Exit]] Function## idiom.

- A ##[[KeyPgSub|Sub]]## cannot specify a return return value. ##**Return**## is roughly equivalent to the ##[[KeyPgExit|Exit]] Sub## idiom.

- In a ##[[KeyPgFunction|Function]]##, ##**Return**## must specify its return value. ##**Return** //expression//## is roughly equivalent to the ##Function = //expression// : [[KeyPgExit|Exit]] Function## idiom.

##### Deletions:

#### Revision [21927]

Edited on 2017-09-29 12:57:57 by fxm [Added (in ยง"See also") a link to the "Labels" page]##### Additions:

- ##[[ProPgLabels|Labels]]##

#### Revision [21810]

Edited on 2017-08-10 09:43:53 by fxm [Corrected typo in "Syntax": RETURN can not be used in functions without returning an expression]##### Additions:

**Return** //expression//

##### Deletions:

##### Additions:

##### Additions:

Control flow statement to return from a procedure or ##[[KeyPgGosub|Gosub]]##.

##**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 roughly 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.

- In the //[[CompilerOptlang|-lang fb]]// dialect ##**Return**## always means return-from-procedure.

- In the //[[CompilerOptlang|-lang qb]]// dialect, ##**Return**## means return-from-gosub by default unless changed with ##[[KeyPgOptionnogosub|Option Nogosub]]##, in which case the compiler will recognize ##**Return**## as return-from-procedure.

- In the //[[CompilerOptlang|-lang fblite]]// dialect, ##**Return**## means return-from-procedure by default unless changed with ##[[KeyPgOptiongosub|Option Gosub]]##, in which case the compiler will recognize ##**Return**## as return-from-gosub.

- None when using the //[[CompilerOptlang|-lang qb]]// dialect.

- ##[[KeyPgSub|Sub]]##

- ##[[KeyPgFunction|Function]]##

- ##[[KeyPgGosub|Gosub]]##

- ##[[KeyPgOptiongosub|Option Gosub]]##

- ##[[KeyPgOptionnogosub|Option Nogosub]]##

##**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 roughly 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.

- In the //[[CompilerOptlang|-lang fb]]// dialect ##**Return**## always means return-from-procedure.

- In the //[[CompilerOptlang|-lang qb]]// dialect, ##**Return**## means return-from-gosub by default unless changed with ##[[KeyPgOptionnogosub|Option Nogosub]]##, in which case the compiler will recognize ##**Return**## as return-from-procedure.

- In the //[[CompilerOptlang|-lang fblite]]// dialect, ##**Return**## means return-from-procedure by default unless changed with ##[[KeyPgOptiongosub|Option Gosub]]##, in which case the compiler will recognize ##**Return**## as return-from-gosub.

- None when using the //[[CompilerOptlang|-lang qb]]// dialect.

- ##[[KeyPgSub|Sub]]##

- ##[[KeyPgFunction|Function]]##

- ##[[KeyPgGosub|Gosub]]##

- ##[[KeyPgOptiongosub|Option Gosub]]##

- ##[[KeyPgOptionnogosub|Option Nogosub]]##

##### Deletions:

##**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 roughly 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.

- In the //[[CompilerOptlang -lang fb]]// dialect ##**Return**## always means return-from-procedure.

- In the //[[CompilerOptlang -lang qb]]// dialect, ##**Return**## means return-from-gosub by default unless changed with ##[[KeyPgOptionnogosub Option Nogosub]]##, in which case the compiler will recognize ##**Return**## as return-from-procedure.

- In the //[[CompilerOptlang -lang fblite]]// dialect, ##**Return**## means return-from-procedure by default unless changed with ##[[KeyPgOptiongosub Option Gosub]]##, in which case the compiler will recognize ##**Return**## as return-from-gosub.

- None when using the //[[CompilerOptlang -lang qb]]// dialect.

- ##[[KeyPgSub Sub]]##

- ##[[KeyPgFunction Function]]##

- ##[[KeyPgGosub Gosub]]##

- ##[[KeyPgOptiongosub Option Gosub]]##

- ##[[KeyPgOptionnogosub Option Nogosub]]##

##### Additions:

##**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 roughly equivalent to the ##Function = //expression// : [[KeyPgExit Exit]] Function## idiom.

##### Deletions:

##### Additions:

'' Return from function

type rational '' simple rational number type

numerator as integer

denominator as integer

'' multiplies two rational types

dim r as rational

'' multiply the divisors ...

r.numerator = r1.numerator * r2.numerator

r.denominator = r1.denominator * r2.denominator

'' ... and return the result

return r

'' display the expression

print r1.numerator & "/" & r1.denominator; " * ";

print r2.numerator & "/" & r2.denominator; " = ";

print r3.numerator & "/" & r3.denominator%%

type rational '' simple rational number type

numerator as integer

denominator as integer

'' multiplies two rational types

dim r as rational

'' multiply the divisors ...

r.numerator = r1.numerator * r2.numerator

r.denominator = r1.denominator * r2.denominator

'' ... and return the result

return r

'' display the expression

print r1.numerator & "/" & r1.denominator; " * ";

print r2.numerator & "/" & r2.denominator; " = ";

print r3.numerator & "/" & r3.denominator%%

##### Deletions:

type rational_number '' simple rational number type

numerator as integer

denominator as integer

type rational as rational_number '' type alias for clearer code

'' multiplies two rational types (note: r1 remains unchanged due to the BYVAL option)

r1.numerator *= r2.numerator '' multiply the divisors ...

r1.denominator *= r2.denominator

return r1 '' ... and return the rational

'' display the expression

'' using STR function 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 )

sleep

end

##### Additions:

'' Return from function in lang FB dialect example

##### Additions:

'' display the expression

'' using STR function to eliminate leading space when printing numeric types

'' using STR function to eliminate leading space when printing numeric types

##### Deletions:

##### Additions:

'' GOSUB & RETURN example, compile with "-lang qb" or use "$lang" as below

type rational_number '' simple rational number type

type rational as rational_number '' type alias for clearer code

r1.numerator *= r2.numerator '' multiply the divisors ...

return r1 '' ... and return the rational

dim as rational r1 = ( 6, 105 ) '' define some rationals r1 and r2

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

end

type rational_number '' simple rational number type

type rational as rational_number '' type alias for clearer code

r1.numerator *= r2.numerator '' multiply the divisors ...

return r1 '' ... and return the rational

dim as rational r1 = ( 6, 105 ) '' define some rationals r1 and r2

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

end

##### Deletions:

type rational_number '' simple rational number type

type rational as rational_number '' type alias for clearer code

r1.numerator *= r2.numerator '' multiply the divisors ...

return r1 '' ... and return the rational

dim as rational r1 = ( 6, 105 ) '' define some rationals r1 and r2

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

end 0

##### Additions:

'$lang: "qb"

Print "Let's Gosub!"

GoSub MyGosub

Print "Back from Gosub!"

Sleep

End

Print "In Gosub!"

Return

Print "Let's Gosub!"

GoSub MyGosub

Print "Back from Gosub!"

Sleep

End

Print "In Gosub!"

Return

##### Deletions:

gosub MyGosub

print "Back from Gosub!"

sleep

end

print "In Gosub!"

return