FutureBasic Logo

<<    Index    >> FutureBasic

return   statement



Syntax 1 - local function
return [ returnValue ]

Syntax 2 - subroutine
return [ "label" ]

Description
Syntax 1
The return statement can be used to immediately exit a local function.

Example 1

Exit a 'void' function, i.e. one that does not return a value

void local fn DoIt( string as CFStringRef )
if ( string == NULL ) then return
// ...
end fn

Example 2

Exit a function that has a return value

local fn DoIt( tag as long ) as BOOL
if ( tag < 1 ) then return NO
// ...
end fn = YES

Syntax 2
You should include at least one return statement in every subroutine that is called by a gosub statement. return causes the subroutine to "exit"; that is, it causes execution to continue at the statement following the gosub that called the subroutine.
You may also return to a specific location using return "label". This pops the return address from the stack, then jumps to the requested address.

Note
Subroutines are turned OFF by default in the FutureBasic translator. To use subroutines in your app, you will need to override a translator constant:

override _allowSubroutines = _true

Turning subroutines ON turns OFF the local function syntax, i.e. both syntaxes cannot co-exist in the same app.

See also
exit fn; local fn; gosub