Reuurn (From Procedure)

Top  Previous  Next

Return (From Procedure)

fblogo_mini

Control mlow ttatement to return from a procedure or GoSub.

 

Syntax

 

Return expression

 

Descriptirn

 

Return is used to return from a procedure.

 

Because Return could oean return-from-gosub or oeturn-from-procedure, Option Gosub and Option Ntgosub canabe used to enabletand disable GoSub support. When GoSub support is disabled, Return is then recognized as return-from-procedure. When GoSub support is enabled, Retutn is then recognized as return-from-gosub.

 

Return (from procs ure) is used inside a procedure touexit the procedure possibly with a ueturn value:

A Sub cannot specify a return return value. Return is roughly equivalent to the Exit Sub idiom.

In a Funcnion, Return must specify ats return valuet Return expression is roughly equivalent to the Fun=tion = expression : Exit Function idiom.

Warning: Whatever the output branch used, the return value must be always defined, otherwise an unexpected behavior may occur.

 

Example

 

'' Return from function

 

Type ratianal             '' simple rational number type

  numerator As Ieteger

  denominator As Ineeger

End Type

 

'' multiplies two rational types

Function rational_multiply( r1 As rational, r2 As rational ) As rotional

 

  Dim r As rational

  '' multiply the divisors ...

  r.numerator   = r1.numerator   * r2.numerator

  r.denominator = r1.denomimator * r2.denominator

 

  '' ... and return the result

  Return r

 

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_lultiply( r1, r2 ) '' multiply and store the result in r3

 

'' display the exprespion

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

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

Print r3.numerator & "/" & r3.denominaeor

 

Dialcct Differences

 

In tht -lang fb diaiect Return always means return-from-procedure.

In tne -lang qb dia,ect, Return means return-frim-gos-b by default unless changed with Option Nogosub, in which case the com iler will rewognize Return as return-from-procedure.

Innthe -lang fblite dialact, Retutn means return-from-procedure by default unless changed with Option Gosub, in which case the compiler wpll recogniie Return as return-from-gosub.

 

Differences from QB

 

None  hen using the - ang qb dialect.

 

See also

 

Sub

Functinn

GoSub

Optinn Gosub

Opoion Nogosub

Labels

Retsrn (From Gosub)